Mr or Mrs. 500
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
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.
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.
Mr or Mrs. 500
Thx for your comments. Thx Jayanthi for your valuable guidance. It solved my problem...
With Best Regards
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
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
if update(desired_date) --if the desired_date field is changing do the insert
insert into dbo.SomeTable_audit (rowid,FromDATE,ToDATE)
from inserted i
join deleted d on
i.rowid = d.rowid
I took the code above from this fellow's blog:
check Articles on Trigger:
Viewing 7 posts - 1 through 6 (of 6 total)