|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
How to add a trigger to my tables
I have three tables, and the situation is we insert the values to table1 and table 2 from one asp page at the same time, and we want the table 3 has the primary key values(ID) of table 1 and 2's new rows after table 1 and 2 inserted. How should I achieve this? If trigger is the way to do, could anyone give some detailed code for this. Thanks very much!
table1 ID col1 col2...... Cus_ID datetime .. .... .... .... 2 x xx A 12:12 ... ... ... ... 7 z zz A 12:13 table 2 ID col1 col2..... Cus_ID datetime .... .... ..... .... 3 x xx A 12:12 .. ... ... ... 4 yy y A 12:13 table 3 ID table1 table2 Cus_ID datetime ... .... ... .... 6 ( 2 ) ( 3 ) A 12:12 ... .... ... ... 9 7 4 A 12:13 |
|
#2
|
||||
|
||||
|
which flavour of database are we talking about here ?
__________________
rgds bdjt |
|
#3
|
|||
|
|||
|
hello
Hi, it is microsoft sql server 2000 I am using. And I use asp code to insert the data into table 1 and table2. I want to update table 3 with the new row IDs from table1 and table2. My case is for tshirt design and table1 is for the data on the front side of Tshirt and table2 is for the backside data. So I want to have table3 as product info which contains the foreign key IDs to access the table1 and table2 for detailed info. Am I made myself clear. I don't know how to create the trigger to make it?? Thanks very much !!
|
|
#4
|
||||
|
||||
|
have a look at : -
http://www.sqlteam.com/item.asp?ItemID=3850 this will tell you how to hand code a trigger that's fired on an insert into table 1 or 2 to write new info to table 3. i'll try and remember to have a look when i get home, as to how to do this through sql server's gui. |
|
#5
|
|||
|
|||
|
Hello, have the code for the table1 like
CREATE TRIGGER upd on dbo.test AFTER INSERT AS if not Exists(Select 1 from product where Inserted.cus_id = product.cus_id and product.systime = Inserted.systime) BEGIN INSERT INTO product VALUES(Inserted.ID,Inserted.cus_id) END ELSE BEGIN Update product Set test_id= Inserted.ID where cus_id = Inserted.cus_id and product.systime = Inserted.systime END But that doesn't work. Do u have some idea about it? Because I a m beginner with this. So need some detailed explanation. Plz help! Thanks a lot for your link. |
|
#6
|
||||
|
||||
|
sbuh
apologies, didn't get to look at this last night and am off to reading festival today, next chance will be monday. if you can't wait that long there are tons of sites out there to help you, google for 'writing triggers for sql server' and you'll find them. let me know if you still hit a wall and i'll fire up a copy of sql server [i now use mySql and took it off my machine] and get a step by step together for you. |
|
#7
|
|||
|
|||
|
Thanks indeed!
Thanks for your sincere help. I think I can search in google frist . IF not succeed, then I post question again. thanks again and regards!
|
![]() |
| Viewing: Dev Shed Forums > Databases > Database Management > How to add a trigger to my tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|