Saturday, 27 July 2013

How to Create the SQL Stored Procedure


Open the SQL server 2005 or 2008 and then create a database and the tables and add the fields as your requirement.Here in this example I use two fields.

ID  int
Name  Varchar(50)

Now Click the New query and the Type following Stored Procedure :

USE [DBNAME]

GO

CREATE procedure Sp_Tblname
@ID int=0,
@Name varchar(50)=null,
@Mode varchar(100)=null
as
begin

if @Mode='Insert'
Insert into Tblname(Name) values (@Name)
end

if @Mode='Update'
begin
update Tblname set Name=@Name where ID=@ID
end

if @Mode='Delete'
begin
Delete from Tblname where ID=@ID
end

if @Mode='Selectall'
begin
Select * from Tblname
end

end

This is the simple stored procedure created using sql.After completing it u can Execute it.
After this u can call these parameters and stored procedure as shown in this link http://sathyadotnet.blogspot.in/search/label/3-Tier%20Architecture.

No comments:

Post a Comment

back to top