蝙蝠岛资源网 Design By www.hbtsch.com
当然有其它工具可以做这件事,但如果客户不允许你在服务器乱装东西时这个脚本就会有用了。
复制代码 代码如下:
DECLARE @tbImportTables table(tablename varchar(128), deleted tinyint)
-- append tables which you want to import
Insert Into @tbImportTables(tablename, deleted) values('tentitytype', 1)
Insert Into @tbImportTables(tablename, deleted) values('tattribute', 1)
-- append all tables
--Insert Into @tbImportTables(tablename, deleted) select table_name, 1 from INFORMATION_SCHEMA.tables where table_type = 'BASE TABLE'
DECLARE @tbImportScripts table(script varchar(max))
Declare @tablename varchar(128),
@deleted tinyint,
@columnname varchar(128),
@fieldscript varchar(max),
@valuescript varchar(max),
@insertscript varchar(max)
Declare curImportTables Cursor For
Select tablename, deleted
From @tbImportTables
Open curImportTables
Fetch Next From curImportTables Into @tablename, @deleted
WHILE @@Fetch_STATUS = 0
Begin
If (@deleted = 1)
begin
Insert into @tbImportScripts(script) values ('Truncate table ' + @tablename)
end
Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' ON')
set @fieldscript = ''
select @fieldscript = @fieldscript + column_name + ',' from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
set @fieldscript = substring(@fieldscript, 0, len(@fieldscript))
set @valuescript = ''
select @valuescript = @valuescript + 'case when ' + column_name + ' is null then ''null'' else '''''''' + convert(varchar(max), ' + column_name + ') + '''''''' end +'',''+' from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
set @valuescript = substring(@valuescript, 0, len(@valuescript) - 4)
set @insertscript = 'select ''insert into ' + @tablename + '(' + @fieldscript + ') values(' + '''+' + @valuescript + ' + '')'' from ' + @tablename
Insert into @tbImportScripts(script) exec ( @insertscript)
Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' OFF')
Insert into @tbImportScripts(script) values ('GO ')
Fetch Next From curImportTables Into @tablename, @deleted
End
Close curImportTables
Deallocate curImportTables
Select * from @tbImportScripts
复制代码 代码如下:
DECLARE @tbImportTables table(tablename varchar(128), deleted tinyint)
-- append tables which you want to import
Insert Into @tbImportTables(tablename, deleted) values('tentitytype', 1)
Insert Into @tbImportTables(tablename, deleted) values('tattribute', 1)
-- append all tables
--Insert Into @tbImportTables(tablename, deleted) select table_name, 1 from INFORMATION_SCHEMA.tables where table_type = 'BASE TABLE'
DECLARE @tbImportScripts table(script varchar(max))
Declare @tablename varchar(128),
@deleted tinyint,
@columnname varchar(128),
@fieldscript varchar(max),
@valuescript varchar(max),
@insertscript varchar(max)
Declare curImportTables Cursor For
Select tablename, deleted
From @tbImportTables
Open curImportTables
Fetch Next From curImportTables Into @tablename, @deleted
WHILE @@Fetch_STATUS = 0
Begin
If (@deleted = 1)
begin
Insert into @tbImportScripts(script) values ('Truncate table ' + @tablename)
end
Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' ON')
set @fieldscript = ''
select @fieldscript = @fieldscript + column_name + ',' from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
set @fieldscript = substring(@fieldscript, 0, len(@fieldscript))
set @valuescript = ''
select @valuescript = @valuescript + 'case when ' + column_name + ' is null then ''null'' else '''''''' + convert(varchar(max), ' + column_name + ') + '''''''' end +'',''+' from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
set @valuescript = substring(@valuescript, 0, len(@valuescript) - 4)
set @insertscript = 'select ''insert into ' + @tablename + '(' + @fieldscript + ') values(' + '''+' + @valuescript + ' + '')'' from ' + @tablename
Insert into @tbImportScripts(script) exec ( @insertscript)
Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' OFF')
Insert into @tbImportScripts(script) values ('GO ')
Fetch Next From curImportTables Into @tablename, @deleted
End
Close curImportTables
Deallocate curImportTables
Select * from @tbImportScripts
标签:
导出插入
蝙蝠岛资源网 Design By www.hbtsch.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
蝙蝠岛资源网 Design By www.hbtsch.com
暂无sqlserver 导出插入脚本代码的评论...
更新日志
2024年12月23日
2024年12月23日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]