新建存储过程 CREATE
--新增用户create procedure addDeviceUser @name nvarchar(36) , @phone nvarchar(36) , @password nvarchar(255)asbegin 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)asbegin 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 endend--执行exec addDeviceUser @name='testname',@phone='18800000000',@password='123'