Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 10-11-2008
Member
 
Join Date: May 2008
Posts: 21
Triggers in SQL

A trigger is a block of code that constitutes a set of T-SQL statements that are activated in response to certain actions .A stored procedure that executes when data in a specified table is modified. Triggers are often created to enforce referential integrity or consistency among logically related data in different tables.

Delete Trigger

This particular code blocks deletion on the table
Fires the trigger whenever deletion use to occur in publishers table

Create trigger xyz (trigger name)
On publishers
For delete
As
Declare @rowdeleted int
Select @rowdeleted =(select count(*) from deleted)’deleted is a magic table where every deleted row is kept until transaction is complete

If@rowdeleted>0
Begin
Raiseerror(‘deletion is not allowed’,12,2)
End

If@rowdeleted>0
Begin
Raiseerror(‘deletion is not allowed’,12,2)
End

Update Trigger

This particular code blocks deletion on the table
Fires the trigger whenever update occurs on publishers table

Create trigger ABC (trigger name)
On publishers
For update
As
If update(pubid)
Begin
Raiserror(‘publisher id cannot be modified’,12,2) ‘raising error
Rollback tran
End
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Triggers in SQL"
Thread Thread Starter Forum Replies Last Post
Battery Swap triggers StreetPass Bug in Nintendo 3DS $Iain$ Portable Devices 6 18-02-2012 06:30 PM
Types of triggers in MySQL Arrosa Software Development 6 14-12-2010 05:11 AM
How to use triggers in Silverlight Laskar Windows Software 6 07-08-2010 09:48 AM
Issues with database and forms triggers Ainsley Software Development 3 29-01-2010 10:11 AM
ASUS Eee box pcs virus triggers recall in Japan Dilbert Portable Devices 1 14-10-2008 06:05 PM


All times are GMT +5.5. The time now is 01:32 PM.