Database Related

Superkey in SQL – Definition And Example

In SQL, a superkey refers to a set of columns present in a table which contains no two rows sharing a similar combination of values. Therefore, each row in the table has its own unique superkey. Moreover, a superkey can simply be a single column as well.

Example of A Superkey

Suppose we have a table holding all the managers in a company, and that table is known as Managers. The columns that the table consists of are named as, Name, Manager Id, Title, and DepartmentID. Since each and every manager possess his/her own ManagerID, therefore that value is always unique for every row present in the table.

This means that for any given row if we combine the ManagerID column value with any other column value, then we will get a unique set of values. Hence, for the combinations like (ManagerID, TItle), (ManagerID, Name), (ManagerID, Name, DepartmentID),(manager ID, Department ID) etc, there are going to be no two rows in the table which will be having exactly similar combination of values, since the ManagerID will always be different and unique for every row. This indicates that combining the Manager ID with any other column(s) will ascertain that this combination too will be unique for all rows in the table.

And that is exactly what is meant by a superkey – it is basically any combination of column(s) for which this combination of values is always going to be unique for all the rows present in a table. Therefore, all those combinations of columns in the Manager table which we discussed above will be regarded as superkeys.

Why Is It Called A Superkey?

The reason why it is known as a superkey is because it is derived from RDBMS theory, as in subset and superset.  Hence, a superkey is necessarily all the superset combinations of keys, which are for sure going to be unique for a row and uniquely identifies it.

Candidate Key versus Superkey

Candidate keys are basically minimal superkeys – so both minimal superkeys and candidate keys are exactly the same. A minimal superkey refers to the minimum number of columns used to identify a single row uniquely.

Leave a Reply