计算机三级数据库辅导:将表数据生成SQL脚本的存储过程和工具

计算机三级数据库辅导:将表数据生成SQL脚本的存储过程和工具,第1张

计算机三级数据库辅导:将表数据生成SQL脚本的存储过程和工具,第2张

从表数据生成SQL脚本的存储过程示例:
createproceduredbo . usputdata @ tablename sysname
as
declare @ column varchar(1000)
declare @ column data varchar(1000)
declare @ SQL varchar(4000)
declare @ xtype tinyint
declare @ name sysname
declare @ objectId int
declare @ declare @ @tablename)=0 -此判断不严格
begin
print ' object not in current database '
return
end
if object property(@ objectid,IsTable') < > 1 -确定对象是否为表
begin
print ' object not table '
return
end
select @ ident = status & 0x 80 from sys columns其中id=@objectid和 c . xtype from sys columns c where c . id = @ objectid order by c . colid
open sys columns _ cursor
set @ column = ' '
set @ column data = ' ' fetch next from sys columns _ cursor into @ name,@ xtype
while @ @ fetch _ status < >-1
begin
if @ @ fetch _ status < >-2
begin if @ xtype not in(189,34, end+@ name
set @ column data = @ column data+case when len(@ column data)= 0 then '' else ','',' ','
end
+case when @ xtype in(167,175)then ' ' ' ' ' ' ' ' ' '+'+@ name+'+' ' ' ' '-varchar,char
when @xtype in(231,239)then ' ' ' '+'+@ name+' ' ' ' ' ' ' ' ' ' ' ')' ' from '+@ TableName[/Br/]print '-'+@ sql[/Br/]exec(@ SQL)[/Br/]if @ ident不为null[/Br/]print ' SET IDENTITY _ INSERT '+@ TableName+' OFF '[/Br/]Go[/Br/]ExecUSPOUTPUTTDATA Your table name[/Br/]工具介绍:
1 InstallShield自带将SQL数据库的结构和数据导出为脚本的功能,非常好用。 如果只是需要打包的话,建议用这个,因为安装文件比较大,如果不是为了打包不建议用。
2 SqlInsert是一个专门将数据导出为脚本的小工具。它没有is那么快,但也一样好用。

位律师回复
DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
白度搜_经验知识百科全书 » 计算机三级数据库辅导:将表数据生成SQL脚本的存储过程和工具

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情