Solved

Merge two tables

Posted on 2004-03-24
5
752 Views
Last Modified: 2008-03-03
I have 2 tables in 2 separate databases called Authors with the following fields:
-AuthId(Identity Field)
-Fname
-Lname

The tables contain book authors from all over the world. One of the tables is North America and the other table is authors from rest of the world. There are many Authors with the same FName and Lname. The only way they are identified is by the Author. Now I want to merge this two tables with a Stored Procedure.

How do I do This??
0
Comment
Question by:AutomaticSlim
  • 2
  • 2
5 Comments
 
LVL 2

Expert Comment

by:dhenson
ID: 10673118
Just for clarification....

Your not looking for a sql to join the two tables together in one result set, but rather a Stored Procedure to create an additional table (dropping if exists) that has all the records from both original tables?

Is that correct?
0
 
LVL 2

Expert Comment

by:dhenson
ID: 10673122
Also....

Did the seeds for the two tables overlap so that the AuthID's would not necessarily be unique?

dhenson
0
 

Author Comment

by:AutomaticSlim
ID: 10673307
Here is an Example:

Authtable1
Id     Fname      LName
1      James       Robertson
2      Mark         Jackson
3      Janet        Ciega


Authtable2
Id     Fname      LName
1      Adam       Pictch
2      Will          Steiner
3      Will          Steiner
4      James       Robertson

Note that James Roberston in Table2 is not same person as James Robertson in Table1.
Now I want to add Authtable2 to Authtable1


Thanks
0
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 50 total points
ID: 10680586
This should do it:

INSERT INTO Authtable1 (FName, LName)
SELECT FName, LName
FROM OtherdbName.dbo.Authtable2


If you want, add a column to the original table for the old AuthId so you can link back to the old table:

ALTER TABLE AuthTable1
ADD OldAuthId INT

Then:

INSERT INTO Authtable1 (FName, LName, OldAuthId)
SELECT Fname, LName, AuthId
FROM OtherdbName.dbo.Authtable2
0
 

Author Comment

by:AutomaticSlim
ID: 10689910
what you suggested above works but now the relationships between my other tables gets unstable and some other issues that I didn't think of.
I guess I asked a question without thinking about it properly.........

Thanks for the help
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now