create table ASD
(
Aid int primary key identity,
Aname varchar(20),
Aprice int,
Asum int ,
Aremark varchar(max)
)
go
create proc All_Proc
(
@Action varchar(20),
@Aid int ,
@Aname varchar(20),
@Aprice int,
@Asum int,
@Aremark varchar(max)
)
as
begin
if(@Action='Insert') --添加
begin
insert into ASD values(@Aname,@Aprice,@Asum,@Aremark)
end
if(@Action='Update') --修改
begin
update ASD set Aname=@Aname,Aprice=@Aprice,Asum=@Asum,Aremark=@Aremark where Aid=@Aid
end
if(@Action='Delete') --删除
begin
delete from ASD where Aid=@Aid
end
if(@Action='Selx') --查询
begin
select * from ASD where Aid=@Aid or Aname like ('%'+@Aname+'%')
end
end
//调用(更换@action要执行的操作,条件根据自身需求进行更改)
declare @aids int
exec All_Proc @Action="update", @aid=1,@Aname='19',@Aprice=12,@Asum=13,@Aremark='14' set @Aids=2
select * from ASD
Sql 一个存储过程实现增删改查
最新推荐文章于 2024-05-22 11:25:36 发布