Thursday, October 4, 2012

Create Procedure in Sql Server Step by Step

create new demo database
CREATE DATABASE demo
use demo Database
USE demo
create new table
CREATE TABLE demoTest
(
 id INT,
 NAME VARCHAR(30),
 ADDR VARCHAR(50)
 )

create Procedure for inserting data into demoTest Table.
CREATE PROC ins_DemoTest
@id  INT,@name  VARCHAR(30),@addr  VARCHAR(30)
AS 
BEGIN
 INSERT INTO demoTest
 (
  id,
  NAME,
  ADDR
 )
 VALUES
 (
  @id,
  @name,
  @addr
 )
END
execute procedure
EXEC ins_DemoTest 1,'Aditya','New Delhi'
EXEC ins_DemoTest 2,'Abhishek','Lucknow'
EXEC ins_DemoTest 3,'Akhilesh','Greater Noida'
EXEC ins_DemoTest 4,'Abhi','Noida'
select data from Table
SELECT * FROM demoTest
id NAME ADDR
1 Aditya New Delhi
2 Abhishek Lucknow
3 Akhilesh Greater Noida
4 Abhi Noida

No comments:

Post a Comment