I'm designing tables in order to map some entities in SQL Server. I have 3 tables which are called legal-applicant, person-applicant and api. person-applicant and legal-applicant refer to one who applies for api. api table refers to information about each kind of api. person-applicant and legal-applicant both are at the same side and have n-m relationship with api table and both of their primary keys are ID that can refer to a person or a company. For implementing this relationship, I made a junction table with two primary keys that one of them is a foreign key for api table and the other (ID) is a foreign key that should refer to both primary keys of person-applicant and legal-applicant. I appreciate if anyone could solve my problem about how to refer 1 foreign key in a junction table to two primary keys (ID) in 2 different table (person-applicant and legal-applicant) in SQL server?
Asked
Active
Viewed 119 times
0
-
1You can't have 2 primary keys in one table. You can have a composite primary key (multiple columns making up one primary key) but it's still just one primary key. Also, constraints can only hold one primary key and one foreign key so what you're suggesting is not possible in SQL-Server. – Xaphas Dec 17 '19 at 06:52
-
1[This answer](https://stackoverflow.com/a/59232905/484814) may be useful. – PerformanceDBA Dec 17 '19 at 07:34
-
Clarify what you want without using the terms "PK" & "FK", because right now you are using them to say things that don't make sense. Except that what youi seem to want is an easily found faq. Also it is an anti-pattern for DB/SQL subtyping/inheritance. Before considering posting please always google any error message or many clear, concise & precise phrasings of your question/problem/goal, with & without your particular strings/names & site:stackoverflow.com & tags, & read many answers. If you post a question, use one phrasing as title. See [ask] & the voting arrow mouseover texts. – philipxy Dec 17 '19 at 07:38
-
Possible duplicate of [Foreign key referring to primary keys across multiple tables?](https://stackoverflow.com/q/668921/3404097) – philipxy Dec 17 '19 at 07:57