Wednesday, August 19, 2009

Stored procedure and Trigger

Stored Procedure

A stored procedure is a subroutine available to applications accessing a relational database system. Stored procedures (sometimes called a sproc or SP) are actually stored in the database data dictionary.

Example



create procedure Empp @eusername nvarchar(20),@epassword nvarchar(20),@EEmpid nvarchar(20)
as
begin
insert into Emp (UserName,PassWord,EmpID) values(@eusername,@epassword,@EEmpid)
end


You can insert the values like this: empp 'Rengan','Nathan','1050'

Trigger

A database trigger is procedural code that is automatically executed in response to certain events on a particular table in a database. Triggers can restrict access to specific data, perform logging, or audit data modifications.

Trigger Example



create trigger tri_update on Emp
for update
as
begin
if update(EmpID)
begin
print'not update here'
rollback transaction
end
end


Regard

Prateek

No comments:

Post a Comment