About primary key, foreign key and unique key
I would like to know about the advantages and disadvantages of primary key, foreign key and unique key. Is it possible to use two null values in unique key?
Â
I would like to know about the advantages and disadvantages of primary key, foreign key and unique key. Is it possible to use two null values in unique key?
Â
Hello Gaynor,
A primary key is very important when designing tables because it helps you organize the data in the table so that it becomes easier to share the data in that table with other tables that may be related to it. With a primary key, you can sort the data in a particular order, so as to be able to suit the environment that you are working in.
A foreign key is also important when it comes to organizing the data in a table, but most importantly it helps in referencing tables that are related to each other so that they can be able to share the related information between each other.
A unique key is more like a primary key, but it has the property that no two values in the range are the same. Whilst a primary key cannot be null, a unique key can be null.
__
Regards
Lee Hung
Primary key is also known as primary keyword. It is a key in a relational database that is unique for every record. It is a unique identifier like for example a driver’s license number, VIN or Vehicle Identification Number, or telephone number which includes an area code. A relational database should only have one primary key which normally appears as columns.
Foreign key is also known as foreign keyword. It is a key in a database table that is from another table that refers to a particular key or targets a particular key, which is usually the primary key, in the table being used. Multiple foreign keys from other tables can target the same single primary key.
But it doesn’t mean that foreign keys should always aim for the primary key. The selection of a primary key in a relational database frequently depends on the administrator’s preference.