Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
Triggers Examples
Triggers Examples
Rate Topic
Display Mode
Topic Options
Author
Message
tochaturvedi-908256
tochaturvedi-908256
Posted Tuesday, October 14, 2008 2:53 AM
Grasshopper
Group: General Forum Members
Last Login: Saturday, March 07, 2009 11:39 PM
Points: 11,
Visits: 22
Hi, Can any one send me the simple examples of using Instead of Trigger and After Trigger with Northwind database tables.
I want to create the triggers and execute them.
Post #585290
GilaMonster
GilaMonster
Posted Tuesday, October 14, 2008 3:10 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:10 AM
Points: 38,079,
Visits: 30,374
What are you trying to do with triggers?
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #585302
tochaturvedi-908256
tochaturvedi-908256
Posted Tuesday, October 14, 2008 4:36 AM
Grasshopper
Group: General Forum Members
Last Login: Saturday, March 07, 2009 11:39 PM
Points: 11,
Visits: 22
The trigger should insert records into tables.
I need only general examples.
Post #585332
vyas
vyas
Posted Tuesday, October 14, 2008 4:41 AM
Hall of Fame
Group: General Forum Members
Last Login: Thursday, May 16, 2013 4:02 AM
Points: 3,131,
Visits: 1,056
Check the following link
http://www.sqlservercentral.com/articles/Triggers/64214/
Post #585336
GilaMonster
GilaMonster
Posted Tuesday, October 14, 2008 5:35 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:10 AM
Points: 38,079,
Visits: 30,374
tochaturvedi (10/14/2008)
The trigger should insert records into tables.
I need only general examples.
CREATE TRIGGER trg_SomeInsert ON SOMETABLE
AFTER INSERT
AS
Insert into someothertable
Select somecolumn from inserted
GO
Does that help at all?
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #585369
tochaturvedi-908256
tochaturvedi-908256
Posted Tuesday, October 14, 2008 5:50 AM
Grasshopper
Group: General Forum Members
Last Login: Saturday, March 07, 2009 11:39 PM
Points: 11,
Visits: 22
Hi Gail,
Thanks for the reply.
I know that the above trigger will fire after insert action to the sometable and insert the records to someothertable.
You used the statement
Select somecolumn from inserted.
What is this inserted? Can i use the sometable inplace of inserted?
Post #585376
GilaMonster
GilaMonster
Posted Tuesday, October 14, 2008 6:10 AM
SSC-Dedicated
Group: General Forum Members
Last Login: Today @ 7:10 AM
Points: 38,079,
Visits: 30,374
tochaturvedi (10/14/2008)
Hi Gail,
Thanks for the reply.
I know that the above trigger will fire after insert action to the sometable and insert the records to someothertable.
Just the one column.
You used the statement
Select somecolumn from inserted.
What is this inserted? Can i use the sometable inplace of inserted?
inserted and deleted are pseudo tables visible only within triggers. The inserted table will contain the rows affected by an insert or the new values of rows affected by an update. The deleted table contains rows affected by the delete or the old values of rows affected by an update.
You can use sometable, but then you'll get all the rows in that table. With inserted, you just get the rows that were inserted by the statement that fired the trigger.
Gail Shaw
Microsoft Certified Master: SQL Server 2008, MVP
SQL In The Wild
: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter
We stand on the bridge and no one may pass
Post #585385
MarlonRibunal
MarlonRibunal
Posted Saturday, October 18, 2008 2:31 PM
Valued Member
Group: General Forum Members
Last Login: Thursday, June 06, 2013 3:51 PM
Points: 68,
Visits: 301
I have posted something about this on my blog. Please follow link below:
http://dbalink.wordpress.com/2008/06/20/how-to-sql-server-trigger-101/
Marlon Ribunal
http://marlonribunal.com
Twitter @MarlonRibunal
Post #588160
« Prev Topic
|
Next Topic »
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.