Wednesday, October 5, 2016

What are the triggers in sqlserver and oracle ?

Trigger is called combination of constrained and store procedure . Trigger only fired when event occur like DML. Automatically executes when events occur. Trigger when to use database administrator some times confuse but in a complex situation it will use.









Sql query:
create trigger tr
on Customer
For insert
AS
DECLARE @count AS INT
SELECT @count = count(Mobile) from Customer where Mobile = 01722001252
if( @count  = 2)
Begin
rollback transaction
PRINT 'NotInserted'
END
ELSE
PRINT 'inserted'

Query Work:

In this query for  create trigger  we write create  trigger and give name tr where  table name Customer. If we want it work for insert we use For insert. Then variable declare @count where we count  the mobile number how many times input. If it more then one time trigger will begin and rollback transaction and print Not Inserted else it will inserted .01722001252 this number can’t be inserted more one times on this table Customer for this trigger name tr.

No comments:

Post a Comment