SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Creating Trigger on View


Creating Trigger on View

Author
Message
shohelr2003
shohelr2003
Right there with Babe
Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)Right there with Babe (787 reputation)

Group: General Forum Members
Points: 787 Visits: 610
Dear,
I have a view that is comprised of multiple tables containing only today's data. I used only select statement in that view. Now I want to write a trigger on that view that when a new row is inserted, it will insert a row into another table.

What can I do for that? Please suggest me in your earlier time.

Regards,
Akbar
e4d4
e4d4
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1177 Visits: 2399
What exactly is your problem? According to BOL "A view can be referenced only by an INSTEAD OF trigger." http://msdn.microsoft.com/en-us/library/ms189799%28v=sql.90%29.aspx
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13316 Visits: 4077
certainly , we can have trigger (instead of) but i will suggest to set the trigger on table.

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Orlando Colamatteo
Orlando Colamatteo
SSC-Dedicated
SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)SSC-Dedicated (39K reputation)

Group: General Forum Members
Points: 39794 Visits: 14412
Bhuvnesh (1/6/2013)
certainly , we can have trigger (instead of) but i will suggest to set the trigger on table.

That likely will not help the situation. There is unique value added to the system when an instead trigger is placed on a view that joins multiple tables. Namely that we can support inserts into that view where before, without the instead trigger, we could not.

From http://msdn.microsoft.com/en-us/library/ms175521(v=sql.105).aspx

The primary advantage of INSTEAD OF triggers is that they enable views that would not be updatable to support updates. A view based on multiple base tables must use an INSTEAD OF trigger to support inserts, updates, and deletes that reference data in more than one table.


__________________________________________________________________________________________________
There are no special teachers of virtue, because virtue is taught by the whole community. --Plato
Bhuvnesh
Bhuvnesh
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13316 Visits: 4077
opc.three (1/6/2013)
Bhuvnesh (1/6/2013)
certainly , we can have trigger (instead of) but i will suggest to set the trigger on table.

That likely will not help the situation. There is unique value added to the system when an instead trigger is placed on a view that joins multiple tables. Namely that we can support inserts into that view where before, without the instead trigger, we could not.

From http://msdn.microsoft.com/en-us/library/ms175521(v=sql.105).aspx

The primary advantage of INSTEAD OF triggers is that they enable views that would not be updatable to support updates. A view based on multiple base tables must use an INSTEAD OF trigger to support inserts, updates, and deletes that reference data in more than one table.
diamond studded link ..thanks :-)

-------Bhuvnesh----------
I work only to learn Sql Server...though my company pays me for getting their stuff done;-)
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search