最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

將表數(shù)據(jù)生成Insert腳本 比較好用的生成插入語(yǔ)句的SQL腳本

 更新時(shí)間:2010年05月13日 19:49:44   作者:  
比較好用的生成插入語(yǔ)句的SQL腳本 將表數(shù)據(jù)生成Insert腳本
復(fù)制代碼 代碼如下:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- =============================================
-- Author: 華嶺
-- Create date: 2008-10-28
-- Description: 將表數(shù)據(jù)生成Insert腳本
-- Demo : exec pCreateInsertScript 'BexmCodeType','dictypeid = 61'
-- =============================================
alter proc [dbo].pCreateInsertScript (@tablename varchar(256),@con nvarchar(400))
as
begin
set nocount on
declare @sqlstr varchar(4000)
declare @sqlstr1 varchar(4000)
declare @sqlstr2 varchar(4000)
select @sqlstr='select ''insert '+@tablename
select @sqlstr1=''
select @sqlstr2='('
select @sqlstr1='values (''+'
select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case
when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =61 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
when a.xtype =62 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
when a.xtype =56 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'
when a.xtype =60 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =108 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
when a.xtype =231 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
when a.xtype =59 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
when a.xtype =58 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
when a.xtype =52 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(12),'+a.name +')'+' end'
when a.xtype =122 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
when a.xtype =127 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end'
when a.xtype =48 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(6),'+a.name +')'+' end'
when a.xtype =165 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
when a.xtype =167 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
else '''NULL'''
end as col,a.colid,a.name
from syscolumns a where a.id = object_id(@tablename)
and a.xtype <>189 and a.xtype <>34 and a.xtype <>35 and a.xtype <>36
)t order by colid
select @sqlstr=@sqlstr+left(@sqlstr2,len(@sqlstr2)-1)+') '+left(@sqlstr1,len(@sqlstr1)-3)+')'' from '+@tablename + ' where 1=1 and ' + isnull(@con,'')
print @sqlstr
exec( @sqlstr)
set nocount off
end

相關(guān)文章

  • MSSQL Server 查詢優(yōu)化方法 整理

    MSSQL Server 查詢優(yōu)化方法 整理

    查詢速度慢的原因很多,常見(jiàn)如下幾種
    2010-03-03
  • sqlserver replace函數(shù) 批量替換數(shù)據(jù)庫(kù)中指定字段內(nèi)指定字符串參考方法

    sqlserver replace函數(shù) 批量替換數(shù)據(jù)庫(kù)中指定字段內(nèi)指定字符串參考方法

    SQL Server有 replace函數(shù),可以直接使用;Access數(shù)據(jù)庫(kù)的replace函數(shù)只能在Access環(huán)境下用,不能用在Jet SQL中,所以對(duì)ASP沒(méi)用,在ASP中調(diào)用該函數(shù)會(huì)提示錯(cuò)誤.
    2010-05-05
  • SQL語(yǔ)句(T-SQL匯總) 用T-SQL畫(huà)出這些圖形

    SQL語(yǔ)句(T-SQL匯總) 用T-SQL畫(huà)出這些圖形

    今天和大家一起來(lái)分享一下SQL語(yǔ)句,T-SQL的用法和語(yǔ)法,以及一些例子,目的是幫助大家一起來(lái)復(fù)習(xí)一下T-SQL的基本語(yǔ)句,以便在項(xiàng)目中更快速的運(yùn)用,當(dāng)然對(duì)于新手來(lái)說(shuō)就更應(yīng)該去學(xué)習(xí)和總結(jié)了
    2012-07-07
  • SQL?Server?2008?R2完美卸載教程(親測(cè)有用)

    SQL?Server?2008?R2完美卸載教程(親測(cè)有用)

    SQL Server 2008 R2是一款非常強(qiáng)大的數(shù)據(jù)庫(kù)管理系統(tǒng),但在某些情況下可能需要卸載它,下面這篇文章主要給大家介紹了關(guān)于SQL?Server?2008?R2完美卸載的相關(guān)資料,需要的朋友可以參考下
    2023-11-11
  • sqlserver 腳本和批處理指令小結(jié)

    sqlserver 腳本和批處理指令小結(jié)

    sqlserver 腳本和批處理指令小結(jié),學(xué)習(xí)sqlserver的朋友可以收藏下
    2012-05-05
  • SQL Server自定義異常raiserror使用示例

    SQL Server自定義異常raiserror使用示例

    這篇文章主要介紹了SQL Server自定義異常raiserror使用示例,本文詳細(xì)的介紹了SQL Server自定義異常的使用,講解如何用“raiserror”來(lái)拋出自定義異常,需要的朋友可以參考下
    2015-07-07
  • SQL參數(shù)化查詢的另一個(gè)理由 命中執(zhí)行計(jì)劃

    SQL參數(shù)化查詢的另一個(gè)理由 命中執(zhí)行計(jì)劃

    為了提高數(shù)據(jù)庫(kù)運(yùn)行的效率,我們需要盡可能的命中執(zhí)行計(jì)劃,這樣就可以節(jié)省運(yùn)行時(shí)間
    2012-08-08
  • 一文掌握SQL的 joins 語(yǔ)法

    一文掌握SQL的 joins 語(yǔ)法

    SQL JOIN是結(jié)合兩個(gè)或多個(gè)表的數(shù)據(jù)的一種方式,INNER JOIN返回兩表匹配的記錄;LEFT JOIN返回左表所有記錄及右表匹配記錄;RIGHT JOIN返回右表所有記錄及左表匹配記錄;FULL JOIN返回兩表中所有記錄,無(wú)論是否匹配,這些JOIN類型有助于靈活查詢和分析關(guān)系數(shù)據(jù)庫(kù)中的數(shù)據(jù)
    2024-09-09
  • SQL Server 常用函數(shù)使用方法小結(jié)

    SQL Server 常用函數(shù)使用方法小結(jié)

    這篇文章主要介紹了SQL Server 常用函數(shù)使用方法小結(jié),需要的朋友可以參考下
    2017-05-05
  • MSSQL存儲(chǔ)過(guò)程的功能和用法詳解

    MSSQL存儲(chǔ)過(guò)程的功能和用法詳解

    Microsoft SQL Server(MSSQL)是一個(gè)關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),它支持各種數(shù)據(jù)操作和查詢功能,其中,存儲(chǔ)過(guò)程是MSSQL中非常重要的一個(gè)功能,在這個(gè)章節(jié)中,我們將詳細(xì)介紹MSSQL存儲(chǔ)過(guò)程的功能和用法
    2023-12-12

最新評(píng)論

团风县| 陇西县| 沁源县| 万盛区| 册亨县| 玛曲县| 沙雅县| 徐州市| 彰化县| 茌平县| 江达县| 辉南县| 潜山县| 周至县| 新营市| 娱乐| 大渡口区| 闸北区| 寻乌县| 陆河县| 汶上县| 临颍县| 万年县| 汉寿县| 洛宁县| 大同县| 富裕县| 特克斯县| 安图县| 锡林郭勒盟| 天等县| 南澳县| 米泉市| 水城县| 壶关县| 怀集县| 民和| 怀仁县| 玉林市| 临城县| 建阳市|