MSSQL存储过程

存储过程的种类:   
    1.系统存储过程。        以sp_开头  
    2.扩展存储过程。        以xp_开头  
    3.用户定义存储过程。

--重新编译存储过程
exec sp_recompile user_procedure 
--执行存储过程
exec sp_recompile user_procedure
--执行存储过程,并给定参数 
exec user_procedure '参数1','参数2'    
--删除存储过程  
drop procedure user_procedure  
--查看存储过程源代码  
exec sp_helptext user_procedure
--建立存储过程
create procedure user_procedure  
--修改存储过程    
alter procedure user_procedure

SQL 循环

declare @id int	
declare @user_name nvarchar(30)	
declare @group_id int

declare user_cur cursor for select * from dbo.dt_user  
open user_cur 
fetch user_cur into @id,@user_name,@group_id
while @@fetch_status=0 
begin   
	--print @id
	update dt_user set group_id=@id where id=@id
	fetch user_cur into @id,@user_name,@group_id	 
end
close user_cur
deallocate user_cur
原文地址:https://www.cnblogs.com/sntetwt/p/9227545.html