当前位置:中国站长下载文章中心数据库区MSSQL → Mssql处理孤立用户的存储过程

Mssql处理孤立用户的存储过程

减小字体 增大字体 作者:佚名  来源:编程中国  发布时间:2008-9-1 18:23:25

以下为引用的内容:

CREATE PROCEDURE [LoneUser]
--INPUT
@DBName             nvarchar(50),
@UserName           nvarchar(50)
AS
    Exec sp_configure 'allow updates','1'
    RECONFIGURE WITH OVERRIDE
   
    Declare @ExecStr nvarchar(4000)
  
    Select @ExecStr = ' Declare @b varbinary(85) '
                    + ' Use Master'
                    + ' Select @b = sid From syslogins Where Name = ''' + @UserName + ''''
                    + ' Use ' + @DBName
                    + ' Update sysusers Set sid = @b Where name = ''' + @UserName + ''''

    --Print @ExecStr
    Exec(@ExecStr)

    Exec sp_configure 'allow updates','0'
    RECONFIGURE WITH OVERRIDE