1. 程式人生 > 資料庫 >SQL server儲存過程

SQL server儲存過程

注意:

①先執行go之前的程式碼

②藍色字型為建立的儲存過程名稱

③建立後,在資料庫中“可編輯性”下的“儲存過程”下可以找到

-----------------------------------------------儲存過程
--無引數查詢
create proc SelectMothod
as
select * from 表名
go
exec SelectMothod
--單引數查詢
create proc SelectMothodDan
@songname nvarchar(50)
as
select * from 表名 where SongName=@songname
go
exec SelectMothodDan 我的天空

--單引數刪除資料
create proc DeleteFangFa
@SGuId char (32)
as
delete from 表名 where SGuId=@SGuId
go
exec DeleteFangFa '0dfca279-c604-4142-a2e6-9c8749bf'
--------------------------------------------------------多引數新增儲存過程
create proc InsertMothod
@SGuId char(32),
@SongName nvarchar(50)
as
insert into 表名 (SGuId,SongName) values (@SGuId,@SongName)

go
exec InsertMothod '18abcc52-497b-481d-b2b3-c0123456','111111'
--------------------------------------------------------更新語句儲存過程
create proc UpdateMothod
@SGuId char(32),
@SongName nvarchar(50),
@Song nvarchar(MAX),
@Singer nvarchar(50),
@SongType int,
@UserID nchar(10),
@UploadTime datetime,
@OnAndOffShif int
as
update 表名 set SongName=@SongName,Song=@Song,Singer=@Singer,SongType=@SongType,UserID=@UserID,UploadTime=@UploadTime,OnAndOffShif=@OnAndOffShif where SGuId=@SGuId
go
exec UpdateMothod '0e0a9f1d-62a9-434d-b7e2-8d97958d','name','sss','sss',11,'11','2020-08-10 23:31:05.000',111