dbms key

DBMS Keys-

DBMS keys are used for identifying record uniquely from table. In table lots of records are saved that all record are saved uniquely or individually is most important. In DBMS keys all that keys are play important role for identify each and every table from database. The keys identifies individually record from table. The keys are also used for relationships between tables with each other. If we want to share two table and sharing data from that two tables then keys are important for joining these tables with each others.


Types of Keys-

  1. Primary key
  2. Foreign key
  3. Candidate key
  4. Super key
  5. Unique key

1. Primary Keys-

Primary key represent table with identical column. If we use primary key in table then that table not accept repeat record for insert. In one table we can use only one primary key. If we use primary key in one column then we cant use another primary key in that table again. Primary key also helps to not accept NULL value for that column also. If we want to join the table then primary is important for join both tables with each other.

In fallowing diagram SID and DeptID is the primary key.

primary key

Benefits of primary key-

  1. Not accept NULL value.
  2. Not accept duplicate values.
  3. Used in table relationship.

2. Foreign Key-

foreign key is important for joining two tables with each other. If we want fetching data from two tables then foreign key is used to find the primary key of next table for join each other. Example-In diagram shows hows connect student table and department table with use of foreign key. In that diagram DeptID is the foreign key from student table because they indicating the primary of department table for table join.

foreign key

3. Candidate Key-

Candidate key is play role after primary key. Primary key works well for one column in table but skip that column all other columns that are indicate user as unique that all fields are indicating as candidate key.

example-In student table S_id indicating primary key but although SID the S_AdharNo and S_PassportNo also indicating as unique identification of student table that called candidate key because they not allow duplicate value for student.

candidate key

4. Super keys-

Super keys gives that all columns whose indicating they all are capable for indicating uniqueness of that table. Super Key is the super set of a candidate key . The primary key also selected from super key for identifying unique records. In fallowing student table S_AdharNo and S_PassportNo is a super key. the primary key also a part of super key because hey indicate the uniqueness of table.

super key

5. Unique Key-

Unique key is used for identifying a unique records from column. If we use unique key then that column accept a unique records only. Unique key work as primary key but primary key not accept NULL values but unique key accept one NULL value.




Leave a Reply