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

首頁 > 開發 > 綜合 > 正文

使用SQL語句創建SQL數據腳本(應對萬網主機部分不支持導出備份數據)

2024-07-21 02:46:21
字體:
來源:轉載
供稿:網友
使用SQL語句創建SQL數據腳本(應對萬網主機部分不支持導出備份數據)1、查詢待導出表Ad中的數據。
SELECT  * FROM [DB_Temp].[dbo].[Ad]
2、編寫存儲過程。
 1 --將表數據生成SQL腳本的存儲過程  2  3 CREATE PROCEDURE dbo.UspOutputData  4 @tablename sysname  5 AS  6 declare @column varchar(1000)  7 declare @columndata varchar(1000)  8 declare @sql varchar(4000)  9 declare @xtype tinyint 10 declare @name sysname 11 declare @objectId int 12 declare @objectname sysname 13 declare @ident int 14 15 set nocount on 16 set @objectId=object_id(@tablename) 17 18 if @objectId is null -- 判斷對象是否存在 19 begin 20 print 'The object not exists' 21 return 22 end 23 set @objectname=rtrim(object_name(@objectId)) 24 25 if @objectname is null or charindex(@objectname,@tablename)=0 --此判斷不嚴密 26 begin 27 print 'object not in current database' 28 return 29 end 30 31 if OBJECTPROPERTY(@objectId,'IsTable') < > 1 -- 判斷對象是否是table 32 begin 33 print 'The object is not table' 34 return 35 end 36 37 select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80 38 39 if @ident is not null 40 print 'SET IDENTITY_INSERT '+@TableName+' ON' 41 42 declare syscolumns_cursor cursor 43 44 for select c.name,c.xtype from syscolumns c where c.id=@objectid order by c.colid 45 46 open syscolumns_cursor 47 set @column='' 48 set @columndata='' 49 fetch next from syscolumns_cursor into @name,@xtype 50 51 while @@fetch_status < >-1 52 begin 53 if @@fetch_status < >-2 54 begin 55 if @xtype not in(189,34,35,99,98) --timestamp不需處理,image,text,ntext,sql_variant 暫時不處理 56 57 begin 58 set @column=@column+case when len(@column)=0 then'' else ','end+@name 59 60 set @columndata=@columndata+case when len(@columndata)=0 then '' else ','','',' 61 end 62 63 +case when @xtype in(167,175) then '''''''''+'+@name+'+''''''''' --varchar,char 64 when @xtype in(231,239) then '''N''''''+'+@name+'+''''''''' --nvarchar,nchar 65 when @xtype=61 then '''''''''+convert(char(23),'+@name+',121)+''''''''' --datetime 66 when @xtype=58 then '''''''''+convert(char(16),'+@name+',120)+''''''''' --smalldatetime 67 when @xtype=36 then '''''''''+convert(char(36),'+@name+')+''''''''' --uniqueidentifier 68 else @name end 69 70 end 71 72 end 73 74 fetch next from syscolumns_cursor into @name,@xtype 75 76 end 77 78 close syscolumns_cursor 79 deallocate syscolumns_cursor 80 81 set @sql='set nocount on select ''insert '+@tablename+'('+@column+') values(''as ''--'','+@columndata+','')'' from '+@tablename 82 83 print '--'+@sql 84 exec(@sql) 85 86 if @ident is not null 87 print 'SET IDENTITY_INSERT '+@TableName+' OFF' 88 89 GO 90 91 exec UspOutputData 你的表名
View Code2、執行存儲過程復制第一行數據:
insert Ad(Id,ParentId,Sorts,Name,Width,Height,Url,Pic,Description,Contents,Time) values(    2,1,0,N'廣告1',0,0,N'www.baidu.com',N'../../Upload/Download/20150327111437.jpg',N'廣告1的內容',N'','2015-03-27 11:14:40.000')
Look!We got it!存儲過程摘自:http://bbs.csdn.net/topics/300135193


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 正镶白旗| 冷水江市| 勃利县| 龙州县| 塔河县| 莱西市| 县级市| 田林县| 昌宁县| 刚察县| 沾化县| 邓州市| 新宾| 义乌市| 乡城县| 海兴县| 台江县| 舒城县| 简阳市| 石柱| 兴城市| 农安县| 吴桥县| 神木县| 吉隆县| 祁阳县| 洞口县| 临朐县| 凤山市| 马山县| 宁阳县| 银川市| 永泰县| 商河县| 江达县| 沭阳县| 吉首市| 绥棱县| 秦皇岛市| 黔南| 宝山区|