Solved

Link tables with primary key

Posted on 2013-06-08
2
492 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how the fundamental information of how to create a table.

747 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

16 Experts available now in Live!

Get 1:1 Help Now