Solved

Link tables with primary key

Posted on 2013-06-08
2
501 Views
Last Modified: 2016-02-11
Hello there,

I have two table which I imported from excel using SSIS. now I am trying to create the link between these tables. I need to transfer the pk of the table1 to table2. please see shot. one way is to
do this for every code but I have around 100,000 records. is there some easy and faster way to this. I am using mssql 2008

UPDATE
    city
SET
    pid = 8
WHERE 
        OstanCode = 10;

Open in new window

db.gif
0
Comment
Question by:zolf
2 Comments
 
LVL 11

Accepted Solution

by:
Deepak Lakkad earned 500 total points
ID: 39232568
Hi,

I assumed that there are two tables named as Table_1 and Table_2.

You want to update PID column of Table_2 with ID column of Table_1.

If I am right, you can try following query to update your second table.


UPDATE	Table_2
SET		pid = Table_1.id
FROM	Table_1
		INNER JOIN Table_2 ON Table_1.code = Table_2.code

Open in new window


- Deepak Lakkad
0
 

Author Closing Comment

by:zolf
ID: 39232790
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

How to increase the row limit in Jasper Server.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

932 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

13 Experts available now in Live!

Get 1:1 Help Now