如何把SQLServer数据库从高版本降级到低版本?
http://blog.csdn.net/dba_huangzj/article/details/7952403
由于目前还广泛使用着SQLServer2000,很多公司又想使用新的SQLServer,从而直接【分离/附加】或者【备份/还原】数据库,在不同版本之间存放。往往就会遇到版本不兼容的问题。前几天遇到了从我本机2008R2上备份的一个数据库还原到2008上面时报错:
从运行版本10.50.2500(2008R2是10.50)和10.00.1600(2008是10.00)中可以看出这个版本不兼容问题,大部分情况下,从低版本升级到高版本,只要不是跨度太大,如2000升级到2012,都不会怎么报错。除非使用了一些新版本不兼容的特性如*=来实现left join的语句。但是就像上图那样,从高版本还原到低版本的时候,问题就出现了,而且几乎一定会报错。
下面给出几个小建议,例子是从2008 降级到2005:
方法一:使用图形化操作(GUI),打开SSMS(SQL Server Management Studio)
步骤1:右键你要降级的数据库,按下图选择:

步骤2:在对话框中选择:

步骤3:在【高级】中选择下图:

步骤4:把脚本保存起来,然后在SQLServer2005中运行脚本。
步骤5:通过【任务】→【导入数据】,把数据从2008导入到使用脚本创建的库上如下图,就完成了:

方法二:使用系统自带的存储过程实现:sp_dbcmptlevel ——将某些数据库行为设置为与指定的 SQL Server 版本兼容
下面是其内部实现代码:
- SET QUOTED_IDENTIFIER ON
- SET ANSI_NULLS ON
- GO
- create procedure sys.sp_dbcmptlevel -- 1997/04/15
- @dbname sysname = NULL, -- database name to change
- @new_cmptlevel tinyint = NULL OUTPUT -- the new compatibility level to change to
- as
- set nocount on
- declare @exec_stmt nvarchar(max)
- declare @returncode int
- declare @comptlevel float(8)
- declare @dbid int -- dbid of the database
- declare @dbsid varbinary(85) -- id of the owner of the database
- declare @orig_cmptlevel tinyint -- original compatibility level
- declare @input_cmptlevel tinyint -- compatibility level passed in by user
- ,@cmptlvl80 tinyint -- compatibility to SQL Server Version 8.0
- ,@cmptlvl90 tinyint -- compatibility to SQL Server Version 9.0
- ,@cmptlvl100 tinyint -- compatibility to SQL Server Version 10.0
- select @cmptlvl80 = 80,
- @cmptlvl90 = 90,
- @cmptlvl100 = 100
- -- SP MUST BE CALLED AT ADHOC LEVEL --
- if (@@nestlevel > 1)
- begin
- raiserror(15432,-1,-1,'sys.sp_dbcmptlevel')
- return (1)
- end
- -- If no @dbname given, just list the valid compatibility level values.
- if @dbname is null
- begin
- raiserror (15048, -1, -1, @cmptlvl80, @cmptlvl90, @cmptlvl100)
- return (0)
- end
- -- Verify the database name and get info
- select @dbid = dbid, @dbsid = sid ,@orig_cmptlevel = cmptlevel
- from master.dbo.sysdatabases
- where name = @dbname
- -- If @dbname not found, say so and list the databases.
- if @dbid is null
- begin
- raiserror(15010,-1,-1,@dbname)
- print ' '
- select name as 'Available databases:'
- from master.dbo.sysdatabases
- return (1)
- end
- -- Now save the input compatibility level and initialize the return clevel
- -- to be the current clevel
- select @input_cmptlevel = @new_cmptlevel
- select @new_cmptlevel = @orig_cmptlevel
- -- If no clevel was supplied, display and output current level.
- if @input_cmptlevel is null
- begin
- raiserror(15054, -1, -1, @orig_cmptlevel)
- return(0)
- end
- -- If invalid clevel given, print usage and return error code
- -- 'usage: sp_dbcmptlevel [dbname [, compatibilitylevel]]'
- if @input_cmptlevel not in (@cmptlvl80, @cmptlvl90, @cmptlvl100)
- begin
- raiserror(15416, -1, -1)
- print ' '
- raiserror (15048, -1, -1, @cmptlvl80, @cmptlvl90, @cmptlvl100)
- return (1)
- end
- -- Only the SA or the dbo of @dbname can execute the update part
- -- of this procedure sys.so check.
- if (not (is_srvrolemember('sysadmin') = 1)) and suser_sid() <> @dbsid
- -- ALSO ALLOW db_owner ONLY IF DB REQUESTED IS CURRENT DB
- and (@dbid <> db_id() or is_member('db_owner') <> 1)
- begin
- raiserror(15418,-1,-1)
- return (1)
- end
- -- If we're in a transaction, disallow this since it might make recovery impossible.
- set implicit_transactions off
- if @@trancount > 0
- begin
- raiserror(15002,-1,-1,'sys.sp_dbcmptlevel')
- return (1)
- end
- set @exec_stmt = 'ALTER DATABASE ' + quotename(@dbname, '[') + ' SET COMPATIBILITY_LEVEL = ' + cast(@input_cmptlevel as nvarchar(128))
- -- Note: database @dbname may not exist anymore
- exec(@exec_stmt)
- select @new_cmptlevel = @input_cmptlevel
- return (0) -- sp_dbcmptlevel
- GO
语法
- sp_dbcmptlevel [ [ @dbname = ] name ]
- [ , [ @new_cmptlevel = ] version ]
参数
- [ @dbname = ] name
-
要为其更改兼容级别的数据库的名称。数据库名称必须符合标识符的规则。name 的数据类型为 sysname,默认值为 NULL。
- [ @new_cmptlevel = ] version
-
数据库要与之兼容的 SQL Server 的版本。version 的数据类型为 tinyint,默认值为 NULL。该值必须为下列值之一:
80 = SQL Server 2000
90 = SQL Server 2005
100 = SQL Server 2008
返回代码值
0(成功)或 1(失败)
注意事项:
如何把SQLServer数据库从高版本降级到低版本?的更多相关文章
- 如何把SQLServer数据库从高版本降级到低版本
如何把SQLServer数据库从高版本降级到低版本 编写人:CC阿爸 2015-4-7 近期在给一个客户推行ECM系统时,基本客户的硬件环境,我们为其安装的为SQL2008 64位的数据库系统.在安装 ...
- SQLserver 数据库高版本无法还原到低版本的数据解决方法
sql server 数据库的版本只支持从上往下兼容.即高版本可以兼容低版本 .低版本不能兼容低版本.通常我们在开发时会用比较高的版本.但是部署到客户那边可能他们的数据库版本会比较低. 我们可以通过导 ...
- 高版本->低版本迁移,低版本客户端连接高版本数据库EXP导出报错EXP-00008,ORA-01455,EXP-00000
生产环境: 源数据库:RHEL + Oracle 11.2.0.3 目标数据库:HP-UX + Oracle 10.2.0.4 需求:迁移部分表 11.2.0.3-->10.2.0.4,若 ...
- 将mssql数据库高版本迁移到低版本
将mssql数据库高版本迁移到低版本 在低版本目标数据库中创建目标空数据库[TargetDb] ,注意新建数据库即可,不要创建任何表 在低版本数据库中,选中[服务器对象=>链接服务器] 右键[新 ...
- 高版本api在低版本中的兼容
直接上例子,看如何避免crash. eg:根据给出路径,获取此路径所在分区的总空间大小. 文档说明:获取文件系统用量情况,在API level 9及其以上的系统,可直接调用File对象的相关方法,以下 ...
- sqlserver 高版本迁移到低版本
奇葩事不少, 这不, 得把 sqlserver 2014 迁移到 2012 开始以为用备份再还原的方法就可以, 谁知道最终兼容性的问题无法解决(低版本不兼容高版本备份的文件, 即便在高版本中选择了兼 ...
- MSSQL数据库高版本迁移到低版本
起因是因为客户要把系统从阿里云迁移到本地服务器,阿里云上的数据库版本是MSSQL2016,客户提供的服务器是Server2008R2的,问题就来了,Server2008不支持2016版本,最后只能装的 ...
- expdp 高版本导入到低版本
低版本 往 高版本 导入,导出的时候不用加version : 高版本往低版本的时候 需要加 version expdp version (往低版本的时候 需要加 version 版本号是 impdp ...
- 解决:高版本jdk编译低版本代码时eclipse提示Access restriction:The type 'Unsafe' is not accessible due to restriction on required library
在Eclipse中采用高版本jdk编译一些低版本的源码时,由于源码中使用了一些高版本中过时的API,可能就会报错,类似于: Access restriction:The type 'Unsafe' i ...
随机推荐
- Linux(Ubuntu 13)下安装Eclipse
1.本机配置及软件情况: Ubuntu版本:Ubuntukylin-13.10-desktop-i386(32位) JDK:jdk1.7.0_15(jdk-7u15-i856.gz) eclipse: ...
- relative与absolute的结合使用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- php5.2.6+apache2.2.15配置
首先下载软件,忘记php下载地址了,apache是官网. 文件名 httpd-2.2.15-win32-x86-openssl-0.9.8m-r2.msi php-5.2.6-win32-instal ...
- JavaWeb学习记录(六)——用户登录功能之Session与验证码验证功能的实现
一.产生验证码的工具类 package blank.util; import java.awt.Color;import java.awt.Graphics;import java.awt.image ...
- spark与storm的对比
对比点 Storm Spark Streaming 实时计算模型 纯实时,来一条数据,处理一条数据 准实时,对一个时间段内的数据收集起来,作为一个RDD,再处理 实时计算延迟度 毫秒级 秒级 吞吐量 ...
- pyCharm使用
1.修改文件和代码模板 修改文件头 2.显示行号
- java 四种内部类和内部接口
/** * 常规内部类:常规内部类没有用static修饰且定义在在外部类类体中. * 1.常规内部类中的方法可以直接使用外部类的实例变量和实例方法. * 2.在常规内部类中可以直接用内部类创建对象 * ...
- Nginx-缓冲原理及优化
一.作用及原理 作用: 使用缓冲释放后端服务器 反向代理的一个问题是代理大量用户时会增加服务器进程的性能冲击影响.在大多数情况下,可以很大程度上能通过利用Nginx的缓冲和缓存功能减轻.当代理到另一台 ...
- Expect安装方法
Expect安装方法 http://bluethink.iteye.com/blog/1079044 Tcl脚本SSHITeyeUnix Expect是基于Tcl语言的一种脚本语言,其实无论是交互还 ...
- Python中strip()函数
在python API中这样解释strip()函数: