declare t_cursor cursor for select name from sysobjects where type='U'
open t_cursor
fetch next from t_cursor into @name
while @@fetch_status=0 begin if exists(select 1 from sysobjects where name=@name and name in ('OAInfo')) exec('select * into test..'+@name+' from '+@name) else if exists(select 1 from sysobjects where name=@name and name in ('Address')) exec('select * into test..'+@name+' from '+@name+' where 1<>1') fetch next from t_cursor into @name end
close t_cursor deallocate t_cursor
go
直接使用DTS(2000)或SSIS(2005)导入导出. 我才不用那个呢, 那样什么都学不会
我什么都不懂,希望能学到点有用的东西, 哪天没有DTS了怎么办...
用DTS吧 方便
手工导入---有数据的 select * into 新库名.dbo.newtab from tab--没有数据的 生成脚本后,再新库里面运行
再判断name是否为你想保留数据的表..
如果是,,则select * into 新库.dbo.表 from 表
不是,,则.select * into 新库.dbo.表 from 表 where 1=2
select * into p..t2 from t1 where 1=2 --有结构无数据
-----------
SQL没有人工智能化
只有判断条件
go
exec sp_msforeachtable 'select * into 新库.? from ? where exists(select 1 from tableName where Name=''?'')'--子查询里输入条件判断就行了
导入有两种选择方式,一种是全表导入,一种是按照你需要的查询条件导入.都满足你的要求.
declare t_cursor cursor for
select name from sysobjects where type='U'
open t_cursor
fetch next from t_cursor into @name
while @@fetch_status=0
begin
if exists(select 1 from sysobjects where name=@name and name in ('OAInfo'))
exec('select * into test..'+@name+' from '+@name)
else if exists(select 1 from sysobjects where name=@name and name in ('Address'))
exec('select * into test..'+@name+' from '+@name+' where 1<>1')
fetch next from t_cursor into @name
end
close t_cursor
deallocate t_cursor
go
我才不用那个呢, 那样什么都学不会
手工导入---有数据的
select * into 新库名.dbo.newtab from tab--没有数据的
生成脚本后,再新库里面运行