当前位置:跳过导航链接计算机毕业设计首页 : 技术应用 : 详细内容

SQL2005修改数据库权限

来源:xiaoniu168.com 作者:管理员 添加时间:2011-09-17 点击数:7663

本文主要介绍从虚拟空间服务器拷贝下来的数据库,还原到本地后,在运行程序后会提示表所属权限的问题,下面就来介绍如何修改数据库表所属权限,话不多说,详见代码:

IF OBJECT_ID('ChangeAll') IS NOT NULL Drop PROC ChangeAll
         GO

         Create PROCEDURE ChangeAll (
             @old sysname,
             @new sysname
         )
        AS
             DECLARE @objname sysname

             SET NOCOUNT ON

             IF USER_ID(@old) IS NULL
                BEGIN
                    RAISERROR ('The @old passed
                does not exist in the database', 16, 1)
                    RETURN
                END
             IF USER_ID(@new) IS NULL
                BEGIN
                    RAISERROR ('The @new passed
                does not exist in the database', 16, 1)
                    RETURN
                END

             DECLARE owner_cursor CURSOR FOR

             Select name FROM sysobjects
              Where uid = USER_ID(@old)
             OPEN owner_cursor
             FETCH NEXT FROM owner_cursor INTO @objname
             WHILE (@@fetch_status <> -1)
                 BEGIN
                     SET @objname = @old + '.' + @objname
                     EXEC sp_changeobjectowner @objname, @new
                     FETCH NEXT FROM owner_cursor INTO @objname
                 END

            CLOSE owner_cursor
            DEALLOCATE owner_cursorz
            GO

             EXEC ChangeAll @old = 'mooip', @new = 'dbo'

--注:mooip:改为原数据库所属用户   dbo是现有用户权限

<责任编辑:计算机毕业设计网(http://www.xiaoniu168.com)>

第1页

【联系方式】

【本站信誉】

用心做计算机毕业设计论文网