Click here to Skip to main content
15,888,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have two tables in SQL Server 2005. First table is 'stock' and second table is 'order'. When user enter something in order table there is an automatic update to some stock value.

e.g
In stock table there is one column: Item and in Item value stored is 500
In order table there is one column: Item
Now, if i enter a order table's item column value as 250 then there should be an automatic update to stock value item column to 250.

I know this can be done using trigger but i do not know how to create trigger. So please help me.

Thanks in advance
Posted
Updated 27-Mar-10 4:18am
v2

Please refer here for create trigger syntax and other helps.

Just searched for a very nice article here inside codeproject,
http://www.codeproject.com/KB/database/OverviewOfTriggers.aspx

Others you might refer,

http://www.dotnetspark.com/kb/657-how-to-create-trigger.aspx

http://msdn.microsoft.com/en-us/library/ms189799.aspx


Thanks
Arindam D Tewary
 
Share this answer
 
v2
You may be better advised to create a stored procedure which does this for you inside a transaction. So you update table 1 then update table2. If both updates are okay then commit the transaction. There are many examples of this both here and by searching with Google.

You'll get a lot of mixed opinions on triggers: I don't mind them but many people dislike them intensely so take the piece of advice that best suits your needs.
 
Share this answer
 

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