March 14, 2007 at 2:52 am
Hello all,
I want to know that, if i want to write trigger in sql server 2005 from where should i do it. or if i want to view trigger which has been already there for table.
plz help me out.
thx in advance
Abhay
March 14, 2007 at 5:59 am
Hi,
you have to write it in query analyzer for a particular table. The procedure is same as in sql server 2000 or from the database expand tables then expand the particular table which u want write the trigger then right click the triggers and u get the "New Trigger" option.
regards,
Jayanthi
March 14, 2007 at 6:20 am
Hi,
Trigger is mainly used for the situation when the db automeically trigger some events.
DML Triggers are,
Insert trigger,update trigger,delete trigger
Assume u write the delete trigger for your table.
whenever a row is deleting that table the trigger will raise and the corresponding codes will be executed.
for ex: In your delete trigger u delete the subcategories and products.
assume trigger table consists of categories.
whenever the category is deleting your delete trigger will raise and autometically corresponding subcategories and products will be deleted.
Like that works all trigger events.
With Regards
Antony
March 15, 2007 at 2:33 am
Hello All,
Thx for your comments. Thx Jayanthi for your valuable guidance. It solved my problem...
With Best Regards
Abhay
November 26, 2008 at 9:16 am
You can get a list of all the triggers in the database by following command in Query Analyzer.
select name from sysobjects where type = 'tr'
you can view the code of a trigger with following command
sp_helptext 'triggername'
June 23, 2011 at 2:35 pm
There's no UI way to write a trigger that I know of, I've always used Query Analyzer to write mine.
Here's a quick example of the syntax of a trigger, of course the tables have to exist for this to work:
create trigger dbo.audit_SomeTable on dbo.SomeOriginTable for update
as
if update(desired_date) --if the desired_date field is changing do the insert
begin
insert into dbo.SomeTable_audit (rowid,FromDATE,ToDATE)
select i.rowid,d.desired_date,i.desired_date
from inserted i
join deleted d on
i.rowid = d.rowid
end
go
I took the code above from this fellow's blog:
http://anthonystechblog.wordpress.com/2011/06/14/how-to-write-a-trigger-in-sql-server/[/url]
August 22, 2011 at 8:44 am
check Articles on Trigger:
http://www.mindstick.com/Articles/d9d0f625-6146-415b-b286-3319e3ec336f/?Trigger%20in%20SQL%20server
http://www.mindstick.com/Articles/8a50890e-16b5-4fc6-8970-54ae61a898f9/?Triggers%20in%20SQL%20Server
http://www.mindstick.com/Articles/f7074849-0e9e-463b-a12d-f3d7a35b2785/?Trigger%20in%20SQL%20Server
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply