因为有新的项目要上线给windows server 2003 系统 由于系统的原因不管怎么也安装不上.net 3.5 sp1 补丁,所以耽误了上线的时间,所以想到了用sql和cmd 命令来把数据导入。
具体步骤如下:
一、先编写sql语句:
:connect .\SQLExpress然后存储为xx.sql文件
USE master
GO
ALTER DATABASE [Whir_ezEIP5_hnnydx201711061481] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
--查看是否还有用户连接
--SELECT * FROM sys.[sysprocesses] WHERE DB_NAME([dbid])='Whir_ezEIP5_hnnydx201711061481'
--GO
ALTER DATABASE [Whir_ezEIP5_hnnydx201711061481] SET MULTI_USER
GO
RESTORE DATABASE [Whir_ezEIP5_hnnydx201711061481] FROM DISK = N'G:\Whir_ezEIP5_hnnydx201711061481_20180110.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
go
ALTER DATABASE [Whir_ezEIP5_hnnydx201711061481] SET SINGLE_USER WITH ROLLBACK IMMEDIATE
GO
--查看是否还有用户连接
--SELECT * FROM sys.[sysprocesses] WHERE DB_NAME([dbid])='cw_sd'
--GO
ALTER DATABASE [Whir_ezEIP5_hnnydx201711061481] SET MULTI_USER
GO
RESTORE DATABASE [cWhir_ezEIP5_hnnydx201711061481] FROM DISK = N'G:\Whir_ezEIP5_hnnydx201711061481_20180110.bak' WITH FILE = 1, NOUNLOAD, REPLACE, STATS = 10
go
二、运行cmd命令,创建数据库
输入:sqlcmd -E -S .\SQLExpress
出现上面提示表示进入数据库成功:
create database Whir_ezEIP5_hnnydx201711061481 //创建数据库
go创建数据库完成。
三、还原数据库
运行cmd 命令:
cmd -i "G:\Whir_ezEIP5_hnnydx201711061481.sql"
还原数据库成功。