Database Management
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesDatabase Management

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

Reply With Quote
  #2  
Old August 20th, 2003, 08:55 AM
bigdavejonnyt's Avatar
bigdavejonnyt bigdavejonnyt is offline
lord of err; master of umm
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: uk
Posts: 92 bigdavejonnyt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 47 m 40 sec
Reputation Power: 6
Send a message via ICQ to bigdavejonnyt
which flavour of database are we talking about here ?
__________________
rgds
bdjt

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

Reply With Quote
  #4  
Old August 20th, 2003, 10:37 AM
bigdavejonnyt's Avatar
bigdavejonnyt bigdavejonnyt is offline
lord of err; master of umm
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: uk
Posts: 92 bigdavejonnyt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 47 m 40 sec
Reputation Power: 6
Send a message via ICQ to bigdavejonnyt
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.

Reply With Quote
  #5  
Old August 20th, 2003, 10:46 AM
SBUH SBUH is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 23 SBUH User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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.

Reply With Quote
  #6  
Old August 21st, 2003, 03:36 AM
bigdavejonnyt's Avatar
bigdavejonnyt bigdavejonnyt is offline
lord of err; master of umm
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2003
Location: uk
Posts: 92 bigdavejonnyt User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 47 m 40 sec
Reputation Power: 6
Send a message via ICQ to bigdavejonnyt
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.

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

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesDatabase Management > How to add a trigger to 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 1 hosted by Hostway