question

binodbabu avatar image
binodbabu asked

Foreign key question

Is there anyway we can restrict duplicate foreign keys being added to a table? i have few tables having 2 times foreign key for same column and reference.
sql-serverforeign-key
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
qamooos avatar image
qamooos answered
Yes , U can CREATE Index On it CREATE Unique Index IDX_YourPrimaryKey on YourTableName (Your Foreign Key Name)
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

@binodbabu A unique index on a column makes sure that the values in that column should remain unique and cannot be duplicated. But I am not too sure why you need a unique foreign key? What is the purpose of that field as a primary key in some other field? It seems like there could be design issues with your schema.
1 Like 1 ·
could you please make it more clear. I am quite new in sql server.Thanks in advance.
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.