Sql-Server

我可以將系統數據庫從一個版本的 SQL Server 移動到另一個版本嗎?

  • March 6, 2012

我們正在將數據庫從一台執行 SQL Server 2005 的電腦轉移到另一台執行 SQL Server 2008 的電腦上。

我正在按照此處找到的步驟,嘗試使用所有使用者登錄名和伺服器級權限複製主數據庫,但是它告訴我備份無法恢復,因為它是由不同版本的伺服器創建的.

有沒有辦法將master數據庫從一個版本的 SQL Server 複製到另一個版本的 SQL Server?

不,您不能將主數據庫(或任何系統數據庫)從一個版本的 SQL Server 移動到另一個版本的 SQL Server。您需要在伺服器上安裝 SQL 2005,然後恢復主伺服器。然後升級到 SQL 2008。

我可能是錯的,但我認為您無法到達那裡(我從未嘗試過)。要將登錄從源伺服器移動到目標伺服器,我使用 Microsoft 的 sp_help_revlogin。要移動數據庫使用者,我使用以下腳本(不是我的,從網上獲取):

SET NOCOUNT ON

SELECT  'USE ' + QUOTENAME(DB_NAME()) 

SELECT  'CREATE USER ' +  QUOTENAME(USER_NAME(rm.member_principal_id)) 
FROM sys.database_role_members AS rm 
WHERE  USER_NAME(rm.member_principal_id) IN 
   (  
       --get user names on the database
       SELECT [name]
       FROM sys.database_principals 
       WHERE [principal_id] > 4 -- 0 to 4 are system users/schemas
       and [type] IN ('G', 'S', 'U') -- S = SQL user, U = Windows user, G = Windows group
   )
ORDER BY rm.role_principal_id ASC


SELECT  'EXEC sp_addrolemember @rolename ='
       + SPACE(1) + QUOTENAME(USER_NAME(rm.role_principal_id), '''') + ', @membername =' + SPACE(1) + QUOTENAME(USER_NAME(rm.member_principal_id), '''') 
FROM    sys.database_role_members AS rm
WHERE   USER_NAME(rm.member_principal_id) IN 
   (  
           --get user names on the database
           SELECT [name]
           FROM sys.database_principals
           WHERE [principal_id] > 4 -- 0 to 4 are system users/schemas
           and [type] IN ('G', 'S', 'U') -- S = SQL user, U = Windows user, G = Windows group
     )

SELECT  
   CASE 
       WHEN perm.state <> 'W' THEN perm.state_desc 
       ELSE 'GRANT'
   END
   + SPACE(1) + perm.permission_name + SPACE(1) + 'ON ' + QUOTENAME(USER_NAME(obj.schema_id)) + '.' + QUOTENAME(obj.name) --select, execute, etc on specific objects
   + CASE
                   WHEN cl.column_id IS NULL THEN SPACE(0)
                   ELSE '(' + QUOTENAME(cl.name) + ')'
     END
   + SPACE(1) + 'TO' + SPACE(1) + QUOTENAME(USER_NAME(usr.principal_id)) COLLATE database_default
   + CASE 
       WHEN perm.state <> 'W' THEN SPACE(0)
       ELSE SPACE(1) + 'WITH GRANT OPTION'
   END

FROM   sys.database_permissions AS perm
INNER JOIN sys.objects AS obj ON perm.major_id = obj.[object_id]
INNER JOIN sys.database_principals AS usr ON perm.grantee_principal_id = usr.principal_id
LEFT JOIN sys.columns AS cl ON cl.column_id = perm.minor_id AND cl.[object_id] = perm.major_id

WHERE obj.name not like 'dt_%' 

引用自:https://dba.stackexchange.com/questions/14497