濮阳杆衣贸易有限公司

主頁(yè) > 知識(shí)庫(kù) > sqlserver 導(dǎo)出插入腳本代碼

sqlserver 導(dǎo)出插入腳本代碼

熱門標(biāo)簽:最新人工智能電銷機(jī)器人 如何做地圖標(biāo)注圖鋪 銀川高頻外呼回?fù)芟到y(tǒng)多少錢 成都電話外呼系統(tǒng)一般多少錢 數(shù)字匠心電銷機(jī)器人 蘭州語(yǔ)音外呼系統(tǒng)運(yùn)營(yíng)商 al智能電話機(jī)器人 陜西電銷外呼系統(tǒng)好用嗎 沒(méi)聽(tīng)見(jiàn)電話機(jī)器人幫你接
當(dāng)然有其它工具可以做這件事,但如果客戶不允許你在服務(wù)器亂裝東西時(shí)這個(gè)腳本就會(huì)有用了。
復(fù)制代碼 代碼如下:

DECLARE @tbImportTables table(tablename varchar(128), deleted tinyint)

-- append tables which you want to import
Insert Into @tbImportTables(tablename, deleted) values('tentitytype', 1)
Insert Into @tbImportTables(tablename, deleted) values('tattribute', 1)
-- append all tables
--Insert Into @tbImportTables(tablename, deleted) select table_name, 1 from INFORMATION_SCHEMA.tables where table_type = 'BASE TABLE'

DECLARE @tbImportScripts table(script varchar(max))

Declare @tablename varchar(128),
@deleted tinyint,
@columnname varchar(128),
@fieldscript varchar(max),
@valuescript varchar(max),
@insertscript varchar(max)

Declare curImportTables Cursor For
Select tablename, deleted
From @tbImportTables

Open curImportTables
Fetch Next From curImportTables Into @tablename, @deleted

WHILE @@Fetch_STATUS = 0
Begin
  If (@deleted = 1)
  begin
    Insert into @tbImportScripts(script) values ('Truncate table ' + @tablename)
  end

  Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' ON')

  set @fieldscript = ''
  select @fieldscript = @fieldscript + column_name + ',' from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
  set @fieldscript = substring(@fieldscript, 0, len(@fieldscript))

  set @valuescript = ''
  select @valuescript = @valuescript + 'case when ' + column_name + ' is null then ''null'' else '''''''' + convert(varchar(max), ' + column_name + ') + '''''''' end +'',''+'   from INFORMATION_SCHEMA.columns where table_name = @tablename and data_type not in('timestamp', 'image')
  set @valuescript = substring(@valuescript, 0, len(@valuescript) - 4)

  set @insertscript = 'select ''insert into ' + @tablename + '(' + @fieldscript + ') values(' + '''+' + @valuescript + ' + '')'' from ' + @tablename
  Insert into @tbImportScripts(script) exec ( @insertscript)

  Insert into @tbImportScripts(script) values ('SET IDENTITY_INSERT ' + @tablename + ' OFF')

  Insert into @tbImportScripts(script) values ('GO ')
  Fetch Next From curImportTables Into @tablename, @deleted
End

Close curImportTables
Deallocate curImportTables

Select * from @tbImportScripts

您可能感興趣的文章:
  • 圖文教程mssqlserver數(shù)據(jù)庫(kù)導(dǎo)出到另外一個(gè)數(shù)據(jù)庫(kù)的方法
  • SQLServer導(dǎo)出數(shù)據(jù)到MySQL實(shí)例介紹
  • SQLServer導(dǎo)出sql文件/表架構(gòu)和數(shù)據(jù)操作步驟
  • sqlserver bcp(數(shù)據(jù)導(dǎo)入導(dǎo)出工具)一般用法與命令詳解
  • SQLServer 數(shù)據(jù)導(dǎo)入導(dǎo)出的幾種方法小結(jié)
  • SQLserver 2008將數(shù)據(jù)導(dǎo)出到Sql腳本文件的方法
  • 使用Navicat Premium將SQLServer數(shù)據(jù)導(dǎo)出為sql格式

標(biāo)簽:遼源 鹽城 朔州 宜春 邢臺(tái) 巴彥淖爾 本溪 通化

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《sqlserver 導(dǎo)出插入腳本代碼》,本文關(guān)鍵詞  sqlserver,導(dǎo)出,插入,腳本,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《sqlserver 導(dǎo)出插入腳本代碼》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于sqlserver 導(dǎo)出插入腳本代碼的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    平顶山市| 綦江县| 定兴县| 石河子市| 招远市| 临邑县| 城口县| 赫章县| 龙井市| 同德县| 遂昌县| 吉木乃县| 汝阳县| 秦皇岛市| 阿拉尔市| 吕梁市| 体育| 曲水县| 晋宁县| 昭苏县| 屯留县| 新宁县| 南陵县| 玛曲县| 琼海市| 舞钢市| 蛟河市| 蓬莱市| 饶阳县| 个旧市| 祁门县| 昌黎县| 安阳市| 郎溪县| 白银市| 固安县| 仙居县| 东兴市| 屯昌县| 无极县| 黎城县|