What is Key in the Database


Tuesday, March 24, 2020

ADVERTISEMENT

What is Key in the Database


What is Key in the Database

Key (Data Base Key)

1) Keys are used to establish and identify relationship between tables in database.
2) They also ensure that each record within a table can be uniquely identified by
combination of one or more fields within a table.
3) There are various keys which plays an important role in designing the database.
Primary Key:
1) The attribute values which are unique within the relation that can be used to
identify the entity/tuples of that table/relation, is called primary key.
2) For example: (1) attribute “Student_Id”, can be used as primary key, since every
student has unique “Student_Id” in a Student database. (2) attribute “Account_No’,
can be used as primary key, since every Customer has unique “Account_No” in a
Bank database.

Super Key or Combination Key:

I) Super Key is defined as a set of attributes, taken collectively, within a table 
uniquely identifies each record within a table.
2) Such keys are also known as combination key. 
combination Key


Candidate Key:

1) Candidate keys are defined as a set of fields from which primary key can be
selected.
2) It is an attribute or set of attributes that can act as a primary key for a table to
uniquely identify each record in that table. 


Secondary or Alternate Key:

1) The candidate key which are not selected for primary key is known as secondary
key or alternate key.
2) In the above table. Either Student_id or Roil_No is primary key and other will be
alternate key.
Non-key Attribute (Non-prime attribute):
1) All attributes other than candidate key attributes are called Non-key attribute.
2) The Non-key attribute is also known as non-prime attributes.
3) In the above table “Name”, “Address” and “course” are non-Key attributes.
Foreign Key:
1) Foreign key is generally a primary key from one table that appears as a field in
another table, where the first table has relationship with second.
2) Non-key of one table, which is a primary key of another table, is called Foreign key
3) Consider a table “Course” that has “course_Id” as primary key and consider another
table “student” that has “course_id” as one of its attribute, then “course_Id” would
be the “foreign Key” in “student” table.

What is Entity in Database



Reactions