This article covers the basic of writing a stored procedure and how to call that from .net. A stored procedure is written using Transact-SQL (T-SQL). T-SQL is a subset of ANSI SQL-92 that has extensions to the Standard. T-SQL includes variables, conditional logic, loops and flow control. A stored procedure allows you to put code or business logic on the database server.
A stored procedure allows for more modular programming. You can create reusable, discrete pieces of functionality using stored procedures. Stored procedures have the parsing and execution plan built at the time they are created so they execute faster than dynamic SQL. If you have a stored procedure that manipulates large amounts of data, that data will remain on the server and not be transported across the network. You can also use stored procedures for security. You can grant users execute permissions on stored procedures without granting those permissions on objects manipulated by those stored procedures.
1. Open SQL Server
2. Create database “employee”
3. Create table “emp”
4. Insert data to the table
1. Create the stored procedure shown below:
create procedure getempproc @city varchar(20)asbeginselect * from emp where city=@cityend