Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 554
  • Last Modified:

Link tables with primary key

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
zolf
Asked:
zolf
1 Solution
 
Deepak LakkadCommented:
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
 
zolfAuthor Commented:
thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now