Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Foreign Key Error Expand / Collapse
Author
Message
Posted Tuesday, June 11, 2013 11:56 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 5, 2013 11:35 AM
Points: 11, Visits: 36
Keep getting this error :

Error :
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'tbl_property' that match the referencing column list in the foreign key 'fk_Trace_num'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

I have created two tables , and am trying to create a relationship but somehow keeps getting the above error.
I have created a composite key in the table and now want to create a foreign key for that in another table.

Kindly advise.
Post #1462304
Posted Tuesday, June 11, 2013 12:02 PM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 2:54 PM
Points: 13,471, Visits: 12,329
sdhamani1020 (6/11/2013)
Keep getting this error :

Error :
Msg 1776, Level 16, State 0, Line 1
There are no primary or candidate keys in the referenced table 'tbl_property' that match the referencing column list in the foreign key 'fk_Trace_num'.
Msg 1750, Level 16, State 0, Line 1
Could not create constraint. See previous errors.

I have created two tables , and am trying to create a relationship but somehow keeps getting the above error.
I have created a composite key in the table and now want to create a foreign key for that in another table.

Kindly advise.


Your table tbl_property does not have a primary key. You have to create one first.


_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Moden's splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
Post #1462308
Posted Tuesday, June 11, 2013 12:43 PM
SSCarpal Tunnel

SSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal TunnelSSCarpal Tunnel

Group: General Forum Members
Last Login: Today @ 1:51 PM
Points: 4,339, Visits: 3,387
Another thing to consider is that the foreign key needs to be the same data type as the primary key.

When considering what to make your primary key, you should take a multitude of things into consideration. This includes that the values will be unique, small in size, static and that they have room to grow.

Unique: They uniquely identify the row, so the values must be unique. Example: Don't use a name.
Small in Size: Also, every nonclustered index will inherit the primary key as a part of the index. The impact on index size and index rows per page dictates that they should be kept small. Example: Don't use a name or nvarchar(255).
Static: The values shouldn't change much because you don't want things shuffled around in the index because you update a value. Example: Don't use a date.
Room to Grow: You don't want to have a key that will run out of room because you won't be able to insert any more rows into the table. Example: Don't use an integer on a table where you expect 250M rows a day.

I am, but no means, the foremost authority on indexing, but this is a decent first-pass list as to how to design your keys. It will give you a decent start in the right direction when creating your nonclustered indexes as well.



Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Post #1462328
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse