sql server - Is it possible to have a relation where the foreign key is also the primary key? -


i have table in sql database should have relation 1 of 2 tables, not both.

my manager solved using id field of table competitor both primary key , foreign key 2 other tables. none of tables have autoincremental ids.

problem is, when try add new compeitor, fails unless there entry in both of other tables specified id, opposite of want.

here illustration show how it's done:

enter image description here

i sorry if has been posted or answered before. not find while searching.

best regards kajac

sure set key foreign , primary on "dependant properties". competitor should have primary key.

public class competitor {   [key]   public int id { get; set; } }  public class equestrain {   [key]   [foreignkey("competitor")]   public int id{ get; set; }    public competitor competitor { get; set; } }  public class teamequestrain {   [key]   [foreignkey("competitor")]   public int id{ get; set; }    public competitor competitor { get; set; } } 

msdn - configuring required optional relationship (one 0 or one)


Comments

Popular posts from this blog

java - Andrioid studio start fail: Fatal error initializing 'null' -

android - Gradle sync Error:Configuration with name 'default' not found -

StringGrid issue in Delphi XE8 firemonkey mobile app -