Ad Code

KEYS concept in DBMS

A Key is a single attribute or combination of two or more attributes of an entity set that is used to identify one or more instances of the set.
  1. PRIMARY KEY: A primary key is a field that uniquely identifies each record in a table. As it uniquely identify each entity, it cannot contain null value and duplicate value. Ex: Consider the customer table, which has field :customer_number, customer_socialsecurity_number, and customer_address.here customer_number of each entity in customer table is distinct so customer-number can be a primary key of customer-table.

  2. SUPER KEY: If we add additional attributes to a primary key, the resulting combination would still uniquely identify an instance of the entity set. Such augmented keys are called superkey. A primary key is therefore a minimum superkey.

  3. CANDIDATE KEY: A nominee's for primary key field are know as candidate key. Ex: From above example of customer table, customer_socialsecurity_number is candidate key as it has all haracteristics of primary key.

  4. ALTERNATE KEY: A candidate key that is not the primary key is called an Alternate key. Ex: In above example, customer_socialsecurity_number is a candidate key but not a primary key so it can be considered as alternate key.

  5. COMPOSITE KEY: Creating more than one primary key are jointly known as composite key. Ex: In above example, if customer_number and customer_socialsecurity_number are made primary key than they will be jointly known as composite key.

  6. FOREIGN KEY: Foreign key is a primary key of master table, which is reference in the current table, so it is known as foreign key in the current table. A foreign key is one or more columns whose value must exist in the primary key of another table. Ex: Consider two tables emp(contains employees description) and emp_edu(contains details of employee's education), so emp_id which is primary key in emp table will be referred as foreign key in emp_edu table.

Post a Comment

0 Comments