Posts

Showing posts from August, 2017

SQL Day 18: Stored Procedure in SQL Server

Image
LO1: What is a Stored Procedure and creating a simple SP LO2: Altering a Stored Procedure LO3: Getting the text of Stored Procedure LO4: Dropping the Stored Procedure LO5: Encrypting the text of Stored Procedure A stored procedure is a group of T-SQL (Transact-SQL) statements. Let’s say we have a situation where we need to execute a query or queries, again and again, we can save that specific query in a stored procedure and call it just by its name. Now we need the employee name and email from tblEmployee table so now we will wrap this query in an SP and execute the SP when required to get the result. Creating a Simple Stored Procedure We can use the Create Procedure command, the syntax is as followed. Syntax: CREATE PROCEDURE AS BEGIN ------Query------- END Example: CREATE PROCEDURE spGetEmployeeName AS BEGIN select name, email from tblEmployee END Once the above command gets executed the SP will be created in the database and will d...