LEARN CODING
Ankush Kushwah Akhilesh Kushwah
Click Here Click Here
Video link : Click Here
key in SQL is an attribute or a set of
A
attributes which helps you uniquely
identify a record or a row of data in a
relation / table.
e are going to see five common
W
types of Keys available in SQL.
Candidate Key
Primary
Primary Key
key Foreign Key
Table 1 Table 2
EmpId EmpName EmpLicence EmpPassport DId DId Department
1001 Akhilesh LC1678 In4578 1 1 IT
1002 Ankush LC3425 Uk6065 2 2 HR
1003 Aakash LC5351 Pk1435 3 3 Finance
Alternate
Alternate Key
key
Primary Key Candidate Key Alternate Key
Super Key
primary key is a table attribute or
A
column that identify every record
present in a table uniquely.
here can be only one primary key
T
attribute in a table and primary key
column element can; be same or Null
value.
EmpId EmpName EmpLicence EmpPassport DId
1001 Ankush LC1678 In4578 1
1002 Akhilesh LC3425 Uk6065 2
1003 Ashish LC5351 Pk1435 3
In the above table, EmpId is the
Primary Key
candidate key is a column or a set of
A
columns the can qualify as a primary
key in the database.
here can be multiple candidate keys
T
in a table and only one candidate Key
can qualify as the primary key.
The candidate key other that the
primary key is called an Alternate key.
Candidate Key
Candidate Key
EmpId EmpName EmpLicence EmpPassport
1001 Ashish LC1678 In4578
1002 Ankush LC3425 Uk6065
1003 Akhilesh
. LC5351 Pk1435
It is the set of columns that helps to
identify rows in a table uniquely.
Super Key
EmpId EmpName EmpLicence EmpPassport DId
1001 Ankush LC1678 In4578 1
1002 Ashish LC3425 Uk6065 2
1003 Akhil LC5351 Pk1435 3
foreign key is a key used to link two
A
tables together. It is sometimes also
called as referencing Key.
Foreign Key
Table 2 Table 2
EmpId EmpName City DId DId Department
1001 Ankush Delhi 1 1 IT
1002 Akhil Noida 2 2 HR
1003 Ashish Agra 3 3 Finance
It is a set of two or more attributes that
helps to identify each tuple in a table
uniquely.
ny key such as super, primary, or
A
candidate key can be called a
composite key if it has more than one
attribute.
Composite Key
EmpId EmpName City EmpPassport
1001 Ashish Agra In4578
1002 Ankush Delhi Uk6065
1003 Akhilesh
. Patna Pk1435
To see more
tech content
LEARN CODING