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.
Thx for your comments. Thx Jayanthi for your valuable guidance. It solved my problem...
With Best Regards
create trigger dbo.audit_SomeTable on dbo.SomeOriginTable for updateasif update(desired_date) --if the desired_date field is changing do the insertbegin 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.rowidendgo