Pages - পৃষ্ঠাসমূহ

Mysql key - Super Key, Candidate Key, Foreign key, Primary key

Candidate key:

A Candidate Key can be any column or a combination of columns that can qualify as unique key in database. There can be multiple Candidate Keys in one table.

In other words Candidate keys are all columns in a table that are not dependent on other columns in the table. All candidate keys are not primary keys. We choose one of the candidate keys as primary key. A table may contain more than one candidate key but only one primary key column per table is allowed.

Primary key:-

The attribute or combination of attributes that uniquely identifies a row or a record. Primary key ensures uniqueness of data in a table so that no two rows in the table can have same value.

create table taslim{
 username varchar(30),
 eamil varchar(30),
 primary key(username)
}engine=myisam;
Foreign Key:-

An attribute or combination of attributes in a table whose value matches a primary key in another table. Foreign key ensures that data entered in a column must be checked with data already entered in the primary key column of another table.

create table productList{
 product_name varchar(30),
 product_no int(100), 
 primary key(product_name)
}engine=myisam;
create table productInfo{
 product_name(40),
 price varchar(30),
 product_desc varchar(120),
 Foreign key(product_name) references productList(product_name)
}engine=myisam;
Foreign Key from mysql.com
Composite key:-

A primary key that consists of two or more attributes is known as composite key

CREATE TABLE userdata (
  userid integer,
  userdataid integer,
  info char(200)
  primary key (userid, userdataid)
);
Candidate key:-

Is a column in a table which has the ability to become a primary key? In some tables there is possibility that more than one column can carry unique values to make sure uniqueness of data all across the table. One of those key columns becomes Primary key and other column become candidate key.

Alternate key:-

In the candidate key the key which is not primary key is the alternate key.

Super key:

A super key is a column or set of columns that uniquely identifies a row within a table.

Different set of attributes which are able to identify any row in the database is known as super key. And minimal super key is termed as candidate key i.e. among set of super keys one with minimum number of attributes. Primary Key could be any key which is able to identify a specific row in database in a unique manner.

Different set of attributes which are able to identify any row in the database is known as super key.

Example:
Given table:  EMPLOYEES {employee_id, firstname, surname, eamil} 
Possible super keys are: 
      {employee_id} 
      {employee_id, firstname} 
      ... 
      (employee_id, firstname, surname,eamil} 
Only the minimal super key - {employee_id} - will be considered as a candidate key. 

1 comment: