I have these table structure in MySQL, and according to my requirement its working fine.
CREATE TABLE `ebasic` ( <br>
`eid` int(11) NOT NULL AUTO_INCREMENT, <br>
`d_id` int(11) NOT NULL, <br>
`pos` varchar(50) DEFAULT NULL, <br>
`hdd` varchar(5) DEFAULT NULL, <br>
`hmm` varchar(10) DEFAULT NULL, <br>
`hyy` varchar(5) DEFAULT NULL, <br>
`fname` varchar(25) DEFAULT NULL, <br>
`lname` varchar(25) DEFAULT NULL, <br>
`bdd` varchar(5) DEFAULT NULL, <br>
`bmm` varchar(10) DEFAULT NULL, <br>
`byy` varchar(5) DEFAULT NULL, <br>
`gender` varchar(10) DEFAULT NULL, <br>
`addr` varchar(100) DEFAULT NULL, <br>
`city` varchar(25) DEFAULT NULL, <br>
`state` varchar(25) DEFAULT NULL, <br>
`pin` varchar(10) DEFAULT NULL, <br>
`country` varchar(25) DEFAULT NULL, <br>
`tel` varchar(25) DEFAULT NULL, <br>
`mobile` varchar(25) DEFAULT NULL, <br>
`email` varchar(30) DEFAULT NULL, <br>
`qual` varchar(30) DEFAULT NULL, <br>
PRIMARY KEY (`eid`) );<br>
CREATE TABLE `eaccount` ( <br>
`eid` int(11) NOT NULL AUTO_INCREMENT, <br>
`d_id` int(11) NOT NULL, <br>
`accno` varchar(20) DEFAULT NULL, <br>
`pan` varchar(15) DEFAULT NULL, <br>
`passport` varchar(15) DEFAULT NULL, <br>
`visa` varchar(15) DEFAULT NULL, <br>
`type` varchar(20) DEFAULT NULL, <br>
KEY `eid` (`eid`), <br>
FOREIGN KEY (`eid`) REFERENCES `ebasic` (`eid`) ON DELETE CASCADE ); <br>
So, the column eid is primary key in ebasic and foreign key in eaccount, so that if row is deleted from ebasic, it gets deleted from eaccount too, because of ON DELETE CASCADE.
But, both of them are auto increment columns, too, so when a row is inserted into ebasic successfully, the corresponding row with eid same as ebasic is inserted into eaccount with auto increment number same.
Now, I am trying to migrate my database to SQL Server, what I have there for auto increment is IDENTITY(seed, increment). But, I can't make foreign key as auto_increment here in SQL Server but in MySQL its possible. Please help !!
ebasicandeaccountsuddenly get out of sync?? This is not a very reliable way to go!! You need to insert intoebasicand then fetch whatevereidyou got, and insert that intoeaccount- anything else is a kludge.... - marc_s