Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
There are 4 table like W,X,Y,Z.

W has 1 primary and auto increment column ID and X,Y,Z have the same ID as a froeign key.
I would like to insert ID in X,Y,Z at the same time when an insert is performed in W, where ID is an auto increment.
Posted
Updated 4-Oct-11 1:02am
v2
Comments
André Kraak 4-Oct-11 7:02am    
Edited question:
Formatted text/code
Spelling/Grammar
Removed shouting
hitech_s 8-Oct-11 8:44am    
insert record to w and get the top record that is recently added to the table then with that id insert to remaining 3 tables

Hi,

Quite interesting problem,

You'll have to do two things while inserting records

1: insert the data in W
2: Get the ID of the last inserted row in W

# 2 can be done this way by executing select query on the base of any information that userentered(but this info should be unique) or on the base of time at which data has been entered for eg select id from w where time='+datetime.Now()

In this way you can get ID of last entered record and then insert it in X Y and Z respctively
 
Share this answer
 
Comments
soniya sangal 4-Oct-11 7:08am    
ITS NOT POSSIBLE TO INSERT AT THE SAME TIME
???
Syed Salman Raza Zaidi 4-Oct-11 7:11am    
http://www.codeproject.com/Answers/242772/How-to-get-information-for-the-last-registered-emp#answer2
check this
soniya sangal 4-Oct-11 7:19am    
I AM NOT GETTING U
Insert value in W
fetch the ID using @@Identity
SQL
Declare @p_ID as int
Insert into W values('abc')
set @p_ID = @@identity

Now insert @p_ID in your other tables
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900