Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 When is a primary key not a primary key?

Author  Topic 

ron2112
Starting Member

44 Posts

Posted - 2011-08-04 : 09:31:25
When trying to create a foreign key, SQL Server 2005 is telling me the primary key on one of my tables does not match an existing primary key...



What am I not understanding here?

thanks!
ron

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-08-04 : 09:34:41
seems like you already have pk constraint. try dropping and recreating the pk.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

ron2112
Starting Member

44 Posts

Posted - 2011-08-04 : 09:49:00
quote:
Originally posted by visakh16

seems like you already have pk constraint. try dropping and recreating the pk.

That's not entirely practical, as there are a number of existing FKs that use this PK, and I would have to go through the process of dismantling them all first, then rebuilding them afterwards. Why those FKs recognize this as a PK and the one I'm trying to create doesn't... I have no idea.

ron
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-08-04 : 10:40:13
What's the exact definition of the primary key (go and script the constraint)

--
Gail Shaw
SQL Server MVP
Go to Top of Page

Sachin.Nand

2937 Posts

Posted - 2011-08-04 : 10:50:05
Are the datatypes same for the columns in both the tables ?

PBUH

Go to Top of Page

ron2112
Starting Member

44 Posts

Posted - 2011-08-04 : 11:13:01
quote:
Originally posted by GilaMonster

What's the exact definition of the primary key (go and script the constraint)

This gave me the answer. The two fields are in the PK in the opposite order than I'd assumed. When I reversed the order of the fields in the FK, SQL Server accepted it with no complaints.

Thank you, I'll keep this in mind for next time.

ron
Go to Top of Page

GilaMonster
Master Smack Fu Yak Hacker

4507 Posts

Posted - 2011-08-04 : 11:28:29
Exactly what I suspected. Glad it's fixed.

--
Gail Shaw
SQL Server MVP
Go to Top of Page
   

- Advertisement -