国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

依賴函數,導出數據腳本

2024-07-21 02:50:08
字體:
來源:轉載
供稿:網友
依賴函數,導出數據腳本

USE [XXX] GO

QUOTED_IDENTIFIER ON GO

ALTER PROCEDURE [dbo].[UspOutputData]

@tablename sysname

AS

declare @column varchar(2000)

declare @columndata varchar(2000)

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 --此判斷不嚴密

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,98) --timestamp不需處理,image,text,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=99 then '''N''''''+convert(nvarchar(max),'+@name+')+''''''''' --ntext 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'


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 萨迦县| 洪湖市| 晋宁县| 江口县| 绥化市| 都昌县| 罗平县| 临安市| 尉氏县| 诸城市| 桂平市| 类乌齐县| 宝兴县| 紫阳县| 彰武县| 涟水县| 洛阳市| 漠河县| 卓资县| 无锡市| 天等县| 岳西县| 芦山县| 罗山县| 和硕县| 荆州市| 长汀县| 老河口市| 剑川县| 上林县| 广东省| 涟水县| 北票市| 望谟县| 八宿县| 定南县| 耒阳市| 准格尔旗| 濉溪县| 五华县| 德保县|