|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to add trigger for 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
|
|||
|
|||
|
Right off the bat: why not combine table 1 and 2 into 1 new table?
A trigger is related to one table and the data modification statements (insert, delete, update). A trigger have no visibility on which row in another table is inserted. Therefore I do not think triggers will work in this situation. But I could be mistaken.. Therefore, I think that you need to do the insert in tables 1 and 2 in a combined stored procedure together with capturing the ID values and the table 3 insert. Hope this helps
__________________
- Rogier Doekes |
|
#3
|
|||
|
|||
|
how about detailed explanation
Hello, I think your idea is good. But could u give some detailed explanation about the coding. I am new to this kind of thing. So need some more info. Thanks again and wait for your reply!
|
|
#4
|
|||
|
|||
|
table 1 and 2 share the CustomerID and the date_time fields.
So the new table has those, together will all the other fields from table 1 and 2 Now you can create the trigger. http://www.devarticles.com/art/1/36 for more information on how to use triggers. |
![]() |
| Viewing: Dev Articles Community Forums > Databases > Microsoft SQL Server > How to add trigger for my tables? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|