Table merging in different databases of SQL2000

Source: Internet
Author: User
Database merging

Q: My account is the ACC database. The two database tables have the same structure.
For example, the first database has a table house.
ID (automatic number) Name Number Address
1 Zhang Yi 001 District 1
2 Zhang 'er 002 District 1
3 zhangsan 003 Zone 2
The second database also has a table house.
ID (automatic number) Name Number Address
1 zhangsan 003 Zone 2
2, 4, 005, zone 1
3 zhangwu006 Zone 2
Objective: To merge data into a database without duplicate information
After merging, it should be
ID (automatic number) Name Number Address
1 Zhang Yi 001 District 1
2 Zhang 'er 002 District 1
3 zhangsan 003 Zone 2
Four tickets, four 005 zones
5 zhangwu 006 Zone 2
Could you tell me how to write an SQL statement or how to manually use it?
Because the data is large, if the master has the SQL database merging method, you can import the data into SQL and then merge it. Question added:On the first floor, you canCodeIs it more detailed? I don't know what to do if the two key databases are connected. A: You can directly use left join.
Insert into database 1. DBO. House (name, number, address)
Select a. Name, A. Number, A. Address
From database 2. DBO. House a left join database 1. DBO. House B
On a. Name = B. Name and A. Number = B. Number and A. Address = B. Address
Where B. Name is null

Or
Insert into database 1. DBO. House (name, number, address)
Select a. Name, A. Number, A. Address
From database 2. DBO. House
Where not exists (select * from database 1. DBO. House where name = A. Name and number = A. number and address = A. Address)

The two writing methods are different in efficiency, depending on the data volume in your table.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.