--1)停止iis exec master..xp_cmdshell 'net stop "IIS Admin Service"' go--2)将数据库db1中中的固定的5个表先导出到数据库db2中(先删除db2,再建立db2),--删除+重建db2 if db_id('db2') is not null drop database db2 create database db2 go--导数据 select * into db2.dbo.表1 from db1.dbo.表1 select * into db2.dbo.表2 from db1.dbo.表2 select * into db2.dbo.表3 from db1.dbo.表3 select * into db2.dbo.表4 from db1.dbo.表4 select * into db2.dbo.表5 from db1.dbo.表5 go--3)然后还原数据库db1 use master go--假设db1的备份文件是c:\db1.bak restore database db1 from disk='c:\db1.bak' go--4)将db1中的这5个表删除 drop table db1.dbo.表1 drop table db1.dbo.表2 drop table db1.dbo.表3 drop table db1.dbo.表4 drop table db1.dbo.表5 go--5)将刚才导出到db2的这5个表导回到db1中 select * into db1.dbo.表1 from db2.dbo.表1 select * into db1.dbo.表2 from db2.dbo.表2 select * into db1.dbo.表3 from db2.dbo.表3 select * into db1.dbo.表4 from db2.dbo.表4 select * into db1.dbo.表5 from db2.dbo.表5 go--6)将这5个表中得一个表(table1)的其中一个字段(stu_id)改成自增。 alter table table1 drop column stu_id goalter table table1 add stu_id int identity go--这是因为导回去的表不再具有自增的属性,所以要重新添加(不同意)--7)最后启动iis exec master..xp_cmdshell 'net start "IIS Admin Service"'
--关于楼主说的"这是因为导回去的表不再具有自增的属性,所以要重新添加"--这个结果是错的,下面的测试说明这个问题create table tempdb.dbo.tb(id int identity) goselect * into master.dbo.tb from tempdb.dbo.tb godrop table tempdb.dbo.tb goselect * into tempdb.dbo.tb from master.dbo.tb godrop table master.dbo.tb goinsert tempdb.dbo.tb select 1 godrop table tempdb.dbo.tb/*--结果: (所影响的行数为 0 行) (所影响的行数为 0 行)服务器: 消息 8101,级别 16,状态 1,行 1 仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'tempdb.dbo.tb' 中为标识列指定显式值。 --*/
net stop "IIS Admin Service--可以成功停止net start "IIS Admin Service--报已经成功启动,可实际上没有启动,所有的iis服务都还是停止 状态另外我希望在停止iis和还原数据库之间有一个延迟,大约1分钟
另外 --6)将这5个表中得一个表(table1)的其中一个字段(stu_id)改成自增。 alter table table1 drop column stu_id goalter table table1 add stu_id int identity go 这里,因为这个表里有数据如果先把该字段删除,再添加,会不会丢失数据或者和原来的id不一样
延迟1分钟:做个测试,你就知道了 select getdate() waitfor delay '00:00:01' select getdate() 改自增: 可以在导入数据的时候用 SET IDENTITY_INSERT dbo.*** ON insert 语句 SET IDENTITY_INSERT dbo.*** Offiis的不知道了
exec master..xp_cmdshell 'net stop "IIS Admin Service"'
go--2)将数据库db1中中的固定的5个表先导出到数据库db2中(先删除db2,再建立db2),--删除+重建db2
if db_id('db2') is not null
drop database db2
create database db2
go--导数据
select * into db2.dbo.表1 from db1.dbo.表1
select * into db2.dbo.表2 from db1.dbo.表2
select * into db2.dbo.表3 from db1.dbo.表3
select * into db2.dbo.表4 from db1.dbo.表4
select * into db2.dbo.表5 from db1.dbo.表5
go--3)然后还原数据库db1
use master
go--假设db1的备份文件是c:\db1.bak
restore database db1 from disk='c:\db1.bak'
go--4)将db1中的这5个表删除
drop table db1.dbo.表1
drop table db1.dbo.表2
drop table db1.dbo.表3
drop table db1.dbo.表4
drop table db1.dbo.表5
go--5)将刚才导出到db2的这5个表导回到db1中
select * into db1.dbo.表1 from db2.dbo.表1
select * into db1.dbo.表2 from db2.dbo.表2
select * into db1.dbo.表3 from db2.dbo.表3
select * into db1.dbo.表4 from db2.dbo.表4
select * into db1.dbo.表5 from db2.dbo.表5
go--6)将这5个表中得一个表(table1)的其中一个字段(stu_id)改成自增。
alter table table1 drop column stu_id
goalter table table1 add stu_id int identity
go--这是因为导回去的表不再具有自增的属性,所以要重新添加(不同意)--7)最后启动iis
exec master..xp_cmdshell 'net start "IIS Admin Service"'
goselect * into master.dbo.tb from tempdb.dbo.tb
godrop table tempdb.dbo.tb
goselect * into tempdb.dbo.tb from master.dbo.tb
godrop table master.dbo.tb
goinsert tempdb.dbo.tb select 1
godrop table tempdb.dbo.tb/*--结果:
(所影响的行数为 0 行)
(所影响的行数为 0 行)服务器: 消息 8101,级别 16,状态 1,行 1
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'tempdb.dbo.tb' 中为标识列指定显式值。
--*/
因为我一直这样做,所以我确定的确是丢失了这个属性。
我不知道为何您用语句就不会?是不是因为我是在企业管理器用导入导出的工具导的,所以会丢失identity的属性呢?
多谢,非常感谢
状态另外我希望在停止iis和还原数据库之间有一个延迟,大约1分钟
--6)将这5个表中得一个表(table1)的其中一个字段(stu_id)改成自增。
alter table table1 drop column stu_id
goalter table table1 add stu_id int identity
go
这里,因为这个表里有数据如果先把该字段删除,再添加,会不会丢失数据或者和原来的id不一样
select getdate()
waitfor delay '00:00:01'
select getdate()
改自增:
可以在导入数据的时候用
SET IDENTITY_INSERT dbo.*** ON
insert 语句
SET IDENTITY_INSERT dbo.*** Offiis的不知道了
您到
http://community.csdn.net/Expert/topic/3450/3450417.xml?temp=.5118219再发一下吧
因为此贴我在您发之前已经揭帖了。