Thứ Năm, 9 tháng 10, 2014

Thực thi một thủ tục trên SQL server 2008 - execute procedure SQL server

1. Tạo DB có tên là DBTest
2. Tạo một bảng User trong DBTest
create table User(UserID int primary key identity(1,1), UserName varchar(50));
insert into User Values('test')
insert into User Values('test2')
3. Nếu chưa có thủ tục ->Tạo thủ tục. Câu lệnh tạo thủ tục
CREATE PROC test(@UserID int)--@UserID là tham số truyền vào kiểu số nguyên
AS
BEGIN
 select Username from User where UserID=@UserID;
END
4. Câu lệnh thực thi
execute test @UserID=1;
5.Kết quả
-- UserName
    test

Không có nhận xét nào: