Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 trigger & table variables

Author  Topic 

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-06 : 02:07:07
can we use tables variables in triggers
if yes please post an example

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-06 : 10:04:07
sure


create trigger foo on mytable for insert as
declare @t table (a int)


however, you didn't say what you wanted to do with the table variable
Go to Top of Page

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-07 : 00:30:56
please give me one sample insert trigger example for getting me good idea about that concept
n thanks for reply n considering me.............
Go to Top of Page

TajKazi
Posting Yak Master

101 Posts

Posted - 2014-11-07 : 00:47:35
also i have some doubts please clear me ..
1] consider in after insert trigger if i am inserting some data in other table than trigger table, within that trigger. when i going to insert some some data in table having trigger at that time ... first data inserted in that other table and then table having trigger is it right or is that happening in any other way

2] also in instead of insert trigger if i don't write insert statement for table having trigger on it. then at the time of inserting data in that particular table having trigger. is data is gets inserted in that table having trigger or not .... cause i didn't write insert statement for that particular statement...........

is it right or not pleas clarify my doubts cause i am a just beginner so help me
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2014-11-07 : 09:57:28
1. for after insert, just like the name says. it happens after the insert into the primary table
2. for instead of, just like the name says, it happens instead of inserting into the primary table

be sure you read the docs and examples on triggers:

http://msdn.microsoft.com/en-us/library/ms189799.aspx
Go to Top of Page
   

- Advertisement -