how can you apply primary keys in multiple columns
It was said in the video that the similarity between the two types (primary and unique) of constraints is that both can be applied to multiple columns, not just a single column. So how do you apply a primary key if there can be only one primary key in a table?
Thanks for reaching out.
There's the possibility to create a composite primary key, where not just a single column, but multiple columns define the uniqueness of the primary key.
For instance, if a single column determines the primary key, all values in the column must be different.
E.g. (id_001), (id_002) etc.
Otherwise, if you are using a composite key, the id column may be combined with, e.g. the date column, so the primary keys become of the following type:
(id_001, '2021-10-24'), (id_001, '2021-10-25'), (id_002, '2021-10-24'), (id_002, '2021-10-30') etc.
Hope this helps.
how do we combine two columns to primary key ? Is there a specific format to define composite primary key?