查出所有新增的表名: select name from db2..sysobjects b where name not in(select name from db1..sysobjects where xtype = 'U') and xtype = 'U'遍历结果集,从db2里一个一个的drop掉
--不管外键约束--删除db2的所有新增表 use db2 goexec sp_msforeachtable @whereand=' and not exists(select * from db1.dbo.sysobjects where name=o.name)', @command1=' drop table ?'
--删除db2的所有新增表 use db2 goexec sp_msforeachtable @whereand=' and not exists(select * from db1.dbo.sysobjects where name collate Chinese_PRC_CI_AS=o.name)', @command1=' drop table ?'
服务器: 消息 1763,级别 16,状态 1,行 1
不支持跨数据库的外键引用。外键 'pubs.dbo.tb'。
服务器: 消息 1750,级别 16,状态 1,行 1
未能创建约束。请参阅前面的错误信息。
select name from db2..sysobjects b where name not in(select name from db1..sysobjects where xtype = 'U') and xtype = 'U'遍历结果集,从db2里一个一个的drop掉
use db2
goexec sp_msforeachtable
@whereand=' and not exists(select * from db1.dbo.sysobjects where name=o.name)',
@command1=' drop table ?'
use db2
goexec sp_msforeachtable
@whereand=' and not exists(select * from db1.dbo.sysobjects where name collate Chinese_PRC_CI_AS=o.name)',
@command1=' drop table ?'