新建存储过程 CREATE
--新增用户
create procedure addDeviceUser
@name nvarchar(36) ,
@phone nvarchar(36) ,
@password nvarchar(255)
as
begin
insert into DeviceUser (id,name,phone,password) values(newid(),@name,@phone,@password)
end
--执行
exec addDeviceUser @name='testname',@phone='18800000000',@password='123'
修改存储过程 ALTER
--新增用户
alter procedure addDeviceUser
@name nvarchar(36) ,
@phone nvarchar(36) ,
@password nvarchar(255)
as
begin
if exists(select 1 from DeviceUser where phone=@phone) --判断用户是否存在
select 1 from DeviceUser where 1!=1
else
begin
insert into DeviceUser (id,name,phone,password) values(newid(),@name,@phone,@password)
select id,name,phone from DeviceUser where phone=@phone
end
end
--执行
exec addDeviceUser @name='testname',@phone='18800000000',@password='123'