久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

將數(shù)據(jù)從一張表導(dǎo)入到另一張表

import data from one table to another table(將數(shù)據(jù)從一張表導(dǎo)入到另一張表)
本文介紹了將數(shù)據(jù)從一張表導(dǎo)入到另一張表的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我使用的是 SQL Server 2008 Enterprise.我需要將服務(wù)器/實(shí)例Server Foo"、數(shù)據(jù)庫(kù)Foo"和表Foo"中的所有數(shù)據(jù)導(dǎo)入目標(biāo)服務(wù)器/實(shí)例Server Goo"、數(shù)據(jù)庫(kù)Goo"和表Goo".Table Foo 和 Table Goo 具有相同的架構(gòu).如果表 Goo 存在相同的行,我想保留 Goo 中的原始數(shù)據(jù)并忽略 Foo 中的導(dǎo)入行(表 Foo 和表 Goo 都有一個(gè)名為 CustomerID 的唯一標(biāo)識(shí)符類(lèi)型列,用作主鍵和聚集索引),只是就像忽略重復(fù)鍵一樣.

I am using SQL Server 2008 Enterprise. I need to import all data from Server/Instance "Server Foo", Database "Foo" and table "Foo", into destination Server/Instance "Server Goo", Database "Goo" and table "Goo". Table Foo and Table Goo are of the same schema. If the same row exists for table Goo, I want to keep the origin data in Goo and ingore the import row in Foo (table Foo and table Goo both has a uniqueidentifier type column called CustomerID which acts as primary key and clustered index), just like ignore duplicate key does.

我正在尋找簡(jiǎn)單可靠的方法來(lái)編寫(xiě) T-SQL 來(lái)解決數(shù)據(jù)導(dǎo)出/導(dǎo)入問(wèn)題.有參考樣本嗎?

I am looking for simple and reliable ways to write T-SQL to solve data export/import issue. Any reference samples?

編輯 1:

我使用 MERGE 嘗試了以下解決方案,但遇到了來(lái)自 SQL Server Management Studio 的以下錯(cuò)誤.任何想法出了什么問(wèn)題?

I have tried the below solution using MERGE, but met with the following error from SQL Server Management Studio. Any ideas what is wrong?

更多信息:

LabTest1\SQLServer2008 => 服務(wù)器\實(shí)例名稱(chēng);OrderDB => 數(shù)據(jù)庫(kù)名稱(chēng);dbo => 模式名稱(chēng);訂單 => 表名.

LabTest1\SQLServer2008 => Server\Instance name; OrderDB => DB name; dbo => schema name; Orders => Table name.

merge into [dbo].[Orders] as Target
using "LabTest1\SQLServer2008.OrderDB.dbo.Orders" as source
on target.Hash = source.Hash
when not matched then
INSERT     ([Hash]
           ,[Order]
           ,[Name]
           ,[CreationTime]
           ,[Description])
     VALUES
     (
     source.[Hash], source.[Order], source.[Name], source.[CreationTime], source.[Description]
     )
when MATCHED then
;

錯(cuò)誤信息:

消息 102,級(jí)別 15,狀態(tài) 1,第 16 行';' 附近的語(yǔ)法不正確.

Msg 102, Level 15, State 1, Line 16 Incorrect syntax near ';'.

提前致謝,喬治

推薦答案

在 SQL Server 2008 中,您可以在 SQL Server Mgmt studio 中編寫(xiě) Goo.Goo 表的腳本,并告訴它創(chuàng)建一個(gè)腳本來(lái)插入所有數(shù)據(jù),使用T-SQL INSERT 語(yǔ)句.轉(zhuǎn)到對(duì)象資源管理器,右鍵單擊數(shù)據(jù)庫(kù),選擇任務(wù) > 生成腳本",選擇要為其生成數(shù)據(jù)插入語(yǔ)句的表,并確保在此處使用此選項(xiàng):

In SQL Server 2008, you could script out your Goo.Goo table in SQL Server Mgmt studio and tell it to also create a script to insert all data by using T-SQL INSERT statements. Go the the Object Explorer, right-click on the database, pick "Tasks > Generate Scripts", pick the table you want to generate the data insert statements for, and make sure to use this option here:

然后可以在另一臺(tái)服務(wù)器上運(yùn)行它們以插入表格內(nèi)容.但是,在這種情況下,您必須自己處理插入可能的現(xiàn)有行.

Those could then be run on the other server to insert the table contents. In this case, however, you'd have to handle inserting possible existing rows yourself.

另一方面,如果兩臺(tái)服務(wù)器在同一網(wǎng)絡(luò)上,您可以使用鏈接服務(wù)器"功能并將源服務(wù)器鏈接到目標(biāo)服務(wù)器,然后使用 SQL Server 2008 MERGE 語(yǔ)句導(dǎo)入所有數(shù)據(jù)從源服務(wù)器的表到目標(biāo)服務(wù)器.

On the other hand, if both servers are on the same network, you could just use the "Linked Server" feature and link the source server to the target server and then use the SQL Server 2008 MERGE statement to import all the data from the source srever's table into the target server.

在對(duì)象資源管理器中,轉(zhuǎn)到服務(wù)器對(duì)象",然后鏈接服務(wù)器",右鍵單擊并添加新鏈接服務(wù)器"以在兩個(gè)服務(wù)器之間建立連接:

In the Object Explorer, go to "Server Objects", then "Linked Servers", right-click and "Add new linked server" to establish a connection between the two servers:

一旦服務(wù)器被鏈接,一個(gè)簡(jiǎn)單的 MERGE 語(yǔ)句(SQL Server 2008 中的新增功能)將允許您合并這兩個(gè)表中的數(shù)據(jù):

Once the servers are linked, a simple MERGE statement (new in SQL Server 2008) will allow you to merge the data from those two tables:

MERGE 
  INTO Goo.Goo as Target
  USING Foo.Foo.dbo.Foo as Source
  ON Source.ID = Target.ID
WHEN NOT MATCHED THEN
  INSERT (field1, field2, field3)
  VALUES (source.field1, source.field2, source.field3)  
WHEN MATCHED THEN
  -- do nothing
;

在此處閱讀有關(guān)新 MERGE 語(yǔ)句的更多信息:

Read more about the new MERGE statement here:

  • http://www.builderau.com.au/program/sqlserver/soa/Using-SQL-Server-2008-s-MERGE-statement/0,339028455,339283059,00.htm
  • http://www.sqlservercentral.com/articles/Advanced+Querying/3122/

或在 SQL Server 2008 聯(lián)機(jī)叢書(shū)中.

or in the SQL Server 2008 Books Online.

馬克

這篇關(guān)于將數(shù)據(jù)從一張表導(dǎo)入到另一張表的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開(kāi)發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱(chēng)轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 欧洲精品在线观看 | 美女视频一区 | 欧美精品一区在线 | 情侣酒店偷拍一区二区在线播放 | 一区二区三区视频在线免费观看 | 激情五月激情综合网 | www.久| 国产精品久久久久久久久免费丝袜 | 99精品在线观看 | 综合天天久久 | 日本高清不卡视频 | 亚洲91视频 | 黄色网址在线免费播放 | 超碰人人在线 | www.99热| 日韩高清国产一区在线 | 久久久妇女国产精品影视 | 99精品国产在热久久 | 色视频一区二区 | 亚洲欧美激情国产综合久久久 | 国产精品日韩 | 亚洲视频免费在线观看 | 欧美一级黄色片 | 懂色av色香蕉一区二区蜜桃 | 久久亚洲一区二区三区四区 | 日韩欧美一区二区三区免费观看 | 国产ts人妖系列高潮 | www.亚洲| 国产成人aⅴ| 日本视频免费 | 欧美精品久久久 | 久久精品视频免费观看 | 91超碰在线观看 | 国产精品123区 | 欧美一区二区三区在线观看视频 | 亚洲精品欧美 | 日本三级电影在线免费观看 | 久久婷婷麻豆国产91天堂 | 91最新在线视频 | 午夜影晥 | 日韩中文字幕在线不卡 |