Okay in this chapter I will explain about store procedure in sql server. Please followng step at bellow:
1. Create database at sql server (In this case I will create dbDatabaseExample)
create database dbDatabaseExample
2. Create table at database (Table Name:tbSTudent)
create table tbStudent(
NO varchar(100) primary key not null, Name varchar(100)
)
3. Fill table data
insert into tbStudent values('0001','Hendry Apryanto')
insert into tbStudent values('0002','Yohan Andreas')
insert into tbStudent values('0003','Tana El San')
4. Create Stored Procedure
A. Stored Procedure without parameter
create procedure SP_SHOWSTUDENT
AS
BEGIN
SELECT * FROM tbStudent
END
Note:
To execute stored procedure use 'exec [STOREPROCEDURE_NAME](EXEC SP_SHOWSTUDENT)'
B. Stored Procedure with parameter
create procedure SP_SHOWSTUDENTPARAMETER
@VARCARI VARCHAR(100)
AS
BEGIN
SELECT * FROM tbStudent WHERE NO=@VARCARI
END
Note:
To execute stored procedure use 'exec [STOREPROCEDURE_NAME][PARAMETER_VALUE](EXEC SP_SHOWSTUDENT('0001'))'
Okay that's is it and congratulation you have make stored procedure in sql server. I hope this tutorial can help you..Thank you...^^GBU
Friday, February 25, 2011
Stored Procedure in SQL Server 2005
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment