简体   繁体   中英

how to create a table with two primary keys where one is foreign key in one table and the other on another table?

I have a table with two primary keys. municipality tables has two entities: municipality_code and municipality_names both primary keys. there is one table postcode which has municipality_code as a foreign key. on the other hand there is another table which has municipality_name as a foreign key. How can I connect them?

You can only have one primary key. But a UNIQUE NOT NULL constraint is just as good as a primary key and can serve as target of a foreign key constraint.

While that solves your immediare problem, I'd suggest that you change the data model so that you always use the same column as target of foreign keys. It makes your data model more understandable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM