SQLServer中数据导出为insert语句
Alter PROCEDURE dbo.UspOutputData set nocount on if @objectId is null -- 判断对象是否存在 if @objectname is null or charindex(@objectname,@tablename)=0 --此判断不严密 if OBJECTPROPERTY(@objectId,'IsTable') < > 1 -- 判断对象是否是table select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80 if @ident is not null declare syscolumns_cursor cursor for select c.name,c.xtype from syscolumns c where c.id=@objectid order by c.colid open syscolumns_cursor while @@fetch_status < >-1 begin set @columndata=@columndata+case when len(@columndata)=0 then '' else ','',' +case when @xtype in(167,175) then '''''''''+'+@name+'+''''''''' --varchar,char end end fetch next from syscolumns_cursor into @name,@xtype end close syscolumns_cursor set @sql='set nocount on select ''insert '+@tablename+'('+@column+') values(''as ''--'','+@columndata+','')'' from '+@tablename print '--'+@sql if @ident is not null GO? ? 存储过程调用语法: exec UspOutputData?表名 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |