亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

用Sql生成數(shù)據(jù)插入Sql腳本

系統(tǒng) 1691 0

CREATE PROCEDURE dbo.UspOutputData @tablename sysname

AS

declare @column varchar(1000)

declare @columndata varchar(1000)

declare @sql varchar(4000)

declare @xtype tinyint

declare @name sysname

declare @objectId int

declare @objectname sysname

declare @ident int

set nocount on

set @objectId=object_id(@tablename)

if @objectId is null -- 判斷對象是否存在

begin

print 'The object not exists'

return

end

set @objectname=rtrim(object_name(@objectId))

if @objectname is null or charindex(@objectname,@tablename)=0 --此判斷不嚴(yán)密

begin

print 'object not in current database'

return

end

if OBJECTPROPERTY(@objectId,'IsTable') < > 1 -- 判斷對象是否是table

begin

print 'The object is not table'

return

end

select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80

if @ident is not null

print 'SET IDENTITY_INSERT '+@TableName+' ON'

declare syscolumns_cursor cursor

for select c.name,c.xtype from syscolumns c where c.id=@objectid order by c.colid

open syscolumns_cursor

set @column=''

set @columndata=''

fetch next from syscolumns_cursor into @name,@xtype

while @@fetch_status < >-1

begin

if @@fetch_status < >-2

begin

if @xtype not in(189,34,35,99,98) --timestamp不需處理,image,text,ntext,sql_variant 暫時不處理

begin

set @column=@column+case when len(@column)=0 then'' else ','end+@name

set @columndata=@columndata+case when len(@columndata)=0 then '' else ','','','

end

+case when @xtype in(167,175) then '''''''''+'+@name+'+''''''''' --varchar,char

when @xtype in(231,239) then '''N''''''+'+@name+'+''''''''' --nvarchar,nchar

when @xtype=61 then '''''''''+convert(char(23),'+@name+',121)+''''''''' --datetime

when @xtype=58 then '''''''''+convert(char(16),'+@name+',120)+''''''''' --smalldatetime

when @xtype=36 then '''''''''+convert(char(36),'+@name+')+''''''''' --uniqueidentifier

else @name end

end

end

fetch next from syscolumns_cursor into @name,@xtype

end

close syscolumns_cursor

deallocate syscolumns_cursor

set @sql='set nocount on select ''insert '+@tablename+'('+@column+') values(''as ''--'','+@columndata+','')'' from '+@tablename

print '--'+@sql

exec(@sql)

if @ident is not null

print 'SET IDENTITY_INSERT '+@TableName+' OFF'

GO

exec UspOutputData Brand

用Sql生成數(shù)據(jù)插入Sql腳本


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 国产精品a在线观看香蕉 | 天天操你 | 日本阿v精品视频在线观看 日本爱爱免费视频 | 国产高清美女一级a毛片久久 | 99爱免费观看视频在线 | 国产性较精品视频免费 | 一区二区三区鲁丝不卡麻豆 | 五月天婷婷视频 | 曰批免费视频播放在线看片二 | 激情欧美一区二区三区中文字幕 | 四虎影院免费视频 | 四虎视频在线 | 亚洲国产天堂久久精品网 | 欧美伊人久久大香线蕉综合69 | 亚洲欧洲尹人香蕉综合 | 99国产精品久久久久久久成人热 | 91视频免费播放 | 奇米影视在线观看 | 四虎精品免费国产成人 | 成人亚洲性情网站www在线观看 | 国产欧美精品一区二区三区-老狼 | 一区二区三区免费视频观看 | 国产伦精品一区二区三区高清 | 六月色婷婷 | 日韩欧美成人免费中文字幕 | www.精东| 玖玖草视频 | 青青青青久在线观看视频 | 国产成人综合久久 | 久草视频在线网 | 四虎永久免费地址在线网站 | 国产成人综合久久综合 | 国产老熟 | 福利视频午夜 | 97精品国产97久久久久久 | 日韩新片王 | 亚洲欧美久久精品1区2区 | 日韩在线 | 中文 | 精品玖玖玖视频在线观看 | 日本成人tv | chinese性中国女人 |