Microsoft SQL Server
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesMicrosoft SQL Server

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old August 20th, 2003, 05:48 AM
SBUH SBUH is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 18 SBUH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #2  
Old August 20th, 2003, 11:41 AM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
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

Reply With Quote
  #3  
Old August 21st, 2003, 01:52 AM
SBUH SBUH is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 18 SBUH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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!

Reply With Quote
  #4  
Old August 22nd, 2003, 10:53 PM
rdoekes rdoekes is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Strasbourg, France
Posts: 181 rdoekes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 m 20 sec
Reputation Power: 7
Send a message via AIM to rdoekes Send a message via Yahoo to rdoekes
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesMicrosoft SQL Server > How to add trigger for my tables?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT