1. 程式人生 > >Sql Server存儲過程詳解

Sql Server存儲過程詳解

ont 提高 exe object 不返回 src 應用程序 存在 color

基本存儲過程

if (exists (select * from sys.objects where name = GetUser)) drop proc GetUser   --判斷存儲過程是否存在,存在則刪除然後重建。
go
create proc GetUser  --創建存儲過程 GetUser
@Id int --參數
as 
set nocount on;  --不返回計數,提高應用程序性能
begin --開始
    select * from [dbo].[User] where Id=@Id  --執行sql語句
end;--結束

調用存儲過程

EXEC GetUser 1
;

執行結果

技術分享圖片

Sql Server存儲過程詳解