sql-server – 将SQL Server 2012备份还原到SQL Server 2008数据库?

前端之家收集整理的这篇文章主要介绍了sql-server – 将SQL Server 2012备份还原到SQL Server 2008数据库?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
有没有办法将sql Server 2012数据库备份还原到sql Server 2008?

我试图附加文件,它不起作用.

解决方法

你有几个选择:

选项A:使用“生成脚本”选项在兼容模式下编写数据库

注意:如果使用模式和数据编写数据库脚本,则根据您的数据大小,脚本将非常庞大,并且不会由SSMS,sqlcmd或osql处理(也可能在GB中).

选项B:

首先使用所有索引,FK等脚本输出表,并在目标数据库中创建空白表 – 仅使用SCHEMA(无数据)选项.

使用BCP插入数据

>使用以下脚本bcp输出数据.在文本模式下设置SSMS并将下面脚本生成输出复制到bat文件中.

  1. -- save below output in a bat file by executing below in SSMS in TEXT mode
  2.  
  3. -- clean up: create a bat file with this command --> del D:\BCP\*.dat
  4.  
  5. select '"C:\Program Files\Microsoft sql Server\100\Tools\Binn\bcp.exe" ' /* path to BCP.exe */
  6. + QUOTENAME(DB_NAME())+ '.' /* Current Database */
  7. + QUOTENAME(SCHEMA_NAME(SCHEMA_ID))+'.'
  8. + QUOTENAME(name)
  9. + ' out D:\BCP\' /* Path where BCP out files will be stored */
  10. + REPLACE(SCHEMA_NAME(schema_id),' ','') + '_'
  11. + REPLACE(name,'')
  12. + '.dat -T -E -SServerName\Instance -n' /* ServerName,-E will take care of Identity,-n is for Native Format */
  13. from sys.tables
  14. where is_ms_shipped = 0 and name <> 'sysdiagrams' /* sysdiagrams is classified my MS as UserTable and we dont want it */
  15. /*and schema_name(schema_id) <> 'unwantedschema' */ /* Optional to exclude any schema */
  16. order by schema_name(schema_id)

>运行bat文件,该文件将在您指定的文件夹中生成.dat文件.
>再次在文本模式下使用SSMS在目标服务器上运行以下脚本.

  1. --- Execute this on the destination server.database from SSMS.
  2.  
  3. --- Make sure the change the @Destdbname and the bcp out path as per your environment.
  4.  
  5. declare @Destdbname sysname
  6. set @Destdbname = 'destinationDB' /* Destination Database Name where you want to Bulk Insert in */
  7. select 'BULK INSERT '
  8. /*Remember Tables must be present on destination database */
  9. + QUOTENAME(@Destdbname) + '.'
  10. + QUOTENAME(SCHEMA_NAME(SCHEMA_ID))
  11. + '.' + QUOTENAME(name)
  12. + ' from ''D:\BCP\' /* Change here for bcp out path */
  13. + REPLACE(SCHEMA_NAME(schema_id),'') + '_' + REPLACE(name,'')
  14. + '.dat'' with ( KEEPIDENTITY,DATAFILETYPE = ''native'',TABLOCK )'
  15. + char(10)
  16. + 'print ''Bulk insert for ' + REPLACE(SCHEMA_NAME(schema_id),'') + ' is done... '''
  17. + char(10) + 'go'
  18. from sys.tables
  19. where is_ms_shipped = 0
  20. and name <> 'sysdiagrams' /* sysdiagrams is classified my MS as UserTable and we dont want it */
  21. and schema_name(schema_id) <> 'unwantedschema' /* Optional to exclude any schema */
  22. order by schema_name(schema_id)

>使用SSMS运行输出以将数据插回表中.

这是非常快速的bcp方法,因为它使用Native模式.

猜你在找的MsSQL相关文章