国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
SqlServer表數(shù)據(jù)導(dǎo)成Insert語(yǔ)句
SqlServer表數(shù)據(jù)導(dǎo)成Insert語(yǔ)句
2010年03月04日 星期四 10:09

create table test(

id int not null constraint pk_test primary key,

name nvarchar(100) null,

description nvarchar(200) null

)

生成insert 語(yǔ)句的SQL如下:

set nocount on

select 'insert into test(id, name, description) values(''' + convert(varchar(10), id) + ''', ''' + name + ''',''' +description + ''')' + char(13) + char(10)

from test --可以加過(guò)濾條件

set nocount off

第二種,利用存儲(chǔ)過(guò)程:

創(chuàng)建:

create     proc   spGenInsertSQL  

@TableName   as   varchar(100)  

as  

--declare   @TableName   varchar(100)  

--set   @TableName   =   'orders'  

--set   @TableName   =   'eeducation'  

DECLARE   xCursor   CURSOR   FOR  

SELECT   name,xusertype  

FROM   syscolumns  

WHERE   (id   =   OBJECT_ID(@TableName) )

declare   @F1   varchar(100)  

declare   @F2   integer  

declare   @SQL   varchar(8000)  

set   @sql   ='SELECT   ''INSERT   INTO   '   +   @TableName   +   '   VALUES('''  

OPEN   xCursor  

FETCH   xCursor   into   @F1,@F2  

WHILE   @@FETCH_STATUS   =   0  

BEGIN  

          set   @sql   =@sql   +  

                              +   case   when   @F2   IN   (35,58,99,167,175,231,239,61)   then   '   +   case   when   '   +   @F1   +   '   IS   NULL   then   ''''   else   ''''''''   end   +   '     else   '+'   end  

                              +   'replace(ISNULL(cast('   +   @F1   +   '   as   varchar(8000)),''NULL''),'''''''','''''''''''')'    

                              +   case   when   @F2   IN   (35,58,99,167,175,231,239,61)   then   '   +   case   when   '   +   @F1   +   '   IS   NULL   then   ''''   else   ''''''''   end   +   '     else   '+'   end  

                              +   char(13)   +   ''','''    

          FETCH   NEXT   FROM   xCursor   into   @F1,@F2  

END  

CLOSE   xCursor  

DEALLOCATE   xCursor  

set   @sql   =   left(@sql,len(@sql)   -   5)   +   '   +   '')''   FROM   '   +   @TableName

exec   (@sql)   

go

執(zhí)行:

exec spGenInsertSQL tablename

刪除:

drop proc spGenInsertSQL

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
將sql server表中的數(shù)據(jù)導(dǎo)出為inert into語(yǔ)句的形式
SQLServer動(dòng)態(tài)建表
自動(dòng)生成表記錄Insert的SQL語(yǔ)句
Sql server中用現(xiàn)有表中的數(shù)據(jù)創(chuàng)建Sql的Insert插入語(yǔ)句
SQL語(yǔ)言快速入門(mén)(二)
我的數(shù)據(jù)庫(kù)學(xué)習(xí)“曲線” - 《程序員》官方BLOG - 博客頻道 - CSD...
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服