Click here to Skip to main content
15,885,740 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
is it is it possible to insert details into two tables at the same time?

i have two tables called registration and student_details i have a few same columns in both tables. so i want to insert the details at the same time in two tables. when user enters details into the registration table at the sametime same columns should be filled in student_details table

Help me thanks
Posted
Updated 17-Dec-13 20:58pm
v2
Comments
thatraja 18-Dec-13 3:02am    
Write Two INSERT statements, that's it
kankeyan 18-Dec-13 3:02am    
Use Trigger
An@nd Rajan10 18-Dec-13 3:08am    
that is not possible, try to two insert query..
Maciej Los 18-Dec-13 3:05am    
Colud you be more specific? Please, provide more details (ex.: sample data, the structure of tables).
thatraja 18-Dec-13 3:12am    
Impossible in this decade :sigh:

1 solution

The best way to approach this would be to create a stored procedure which takes all the details as parameters, and uses a Transaction to ensure that either both updates are done, or neither of them.
If you have a look here: http://www.4guysfromrolla.com/webtech/080305-1.shtml[^] it gives an example, but using deletes instead of inserts, but the principle is exactly the same.
 
Share this answer
 
Comments
Maciej Los 18-Dec-13 3:21am    
+5, Paul!

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