How To Create Stored Peocedure In SQL Server

In this article we will learn how to create the stored procedure in SQL server .Before lets see definition of stored procedure

What is a Stored Procedure?
A Stored Procedure is a group of logical SQL statements to perform a specific task, such as insert, select, update and delete operations on a table and so on which is stored in a SQL database.
 . There are two ways to create procedure
  1. Using wizard
  2. Using create keyword
Using wizard

Follow the following steps to create stored procedure
  1. Login into your SQL Server management studio
  2. Expand Databases  option
  3. After expanding the databases option select the specific database in which you wants to create stored procedure .
  4. After expanding the specific database find sub folder Stored procedure under Programmability folder .
  5. Now right click on Stored procedure folder and click on New stored procedure as shown in below

After clicking on New stored procedure option then some default code will be generated ,modify that default code as your need and create procedure.

Using create keyword 

Use the following code to create stored procedure using create keyword

Create Procedure AddEmployee
(
 --variable  declareations   
@id int=null,                                   
@Fname Varchar (50)=null,                    
@MName Varchar (50)=null,                    
@Lname Varchar (50)=null  
)
as
Begin
Insert Into employee (FirstName,MName,LastName)values(@Fname,@MName,@Lname)
End  
Watch Video


Summary

I hope this article is useful for all readers..if you have any suggestion related to this article then please contact me.

Post a Comment

www.CodeNirvana.in

Protected by Copyscape
Copyright © Compilemode