Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Old Forums
 CLOSED - General SQL Server
 Data Insertion in multiple tables.

Author  Topic 

Mohammed222
Starting Member

1 Post

Posted - 2007-05-16 : 05:16:17
Hi,
How can i insert similar id in two different tables.

eg:I have customer table and contact table, 'cust_custid' is a field in customer table and 'cndt_cndtid' is a field in contact table,
i created a field 'cndt_custid' in contact table,whenever a entry is made in customer table,i want 'cndt_cndtid' field in contact table to be automatically filled with respect to 'cust_custid'.

Kindly suggest.

Note:Primary key in customer table is 'cust_custid'and 'cndt_custid' is made as foreign key.

shallu1_gupta
Constraint Violating Yak Guru

394 Posts

Posted - 2007-05-17 : 00:47:40
you can have a trigger on Insert of Customer Table that will Insert a Row in COntact table with cndt_custid equal to Customer Id of Customer Table.
Go to Top of Page

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2007-05-18 : 07:13:59
Is the entry made with an insert or a SP ???

You can also call a SP, and use the scope_identity() function to retrieve the value from your table and insert into the other.
Go to Top of Page
   

- Advertisement -