how to create store procedure

Post on 11-Apr-2017

89 Views

Category:

Education

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Storeprocedure:

A stored procedure is nothing more than prepared SQL code that you save so you can reuse the code over and over again.  So if you think about a query that you write over and over again, instead of having to write that query each time you would save it as a stored procedure and then just call the stored procedure to execute the SQL code that you saved as part of the stored procedure.

SP is pre-define and pre-compiled set of souce code.

To create a stored procedure to do this the code would look like this:

CREATE PROCEDURE GetEmployeeDetails      @EmployeeID int = 0ASBEGIN      SET NOCOUNT ON;      SELECT FirstName, LastName, BirthDate, City, Country      FROM Employees WHERE EmployeeID=@EmployeeIDEND

GO

Alter or Modify a Stored Procedure

ALTER PROCEDURE GetEmployeeDetails      @EmployeeID int = 0ASBEGIN      SET NOCOUNT ON;      SELECT FirstName, LastName, BirthDate, City, Country      FROM Employees WHERE EmployeeID=@EmployeeIDEND

GO

Below figure displays the syntax for alter a stored procedure. As you can see below to modify a stored

procedure ALTER keyword is used rest all remains the same.

Drop or Delete a Stored Procedure

Figure below displays how to drop a stored procedure. As you can see below to delete a stored

procedure DROP keyword is used proceeded by the name of the stored procedure.

Example

DROP PROCEDURE GetEmployeeDetails

 

top related