Hello Readers,
Today I am writing about an important type of database, Relational Databases.
Relational Database is a type of database. The data is organized in the form of relations i.e. Tables. A table contain the attributes and tuples . In simple words, attributes are columns and tuples are rows. The attributes define qualities about an entity. A tuple contains value for a particular attribute of an entity.
Lets take an example.
PERSON
Here is relation named Person. The attributes of this relation are : Person_ID , Name, Age, Place. There are three tuples inserted into the Person relation.
Primary Key
A primary key is an attribute that uniquely identifies tuples in a relation.
Here PERSON_ID is taken as primary key in the person relation , it uniquely identifies each person (each tuple) .
Primary key should be unique . It should not be repeated in any tuple.
Primary key cannot contain NULL values. It must contain data.
A table can have only one primary key.
Alternate Keys
The attributes that uniquely identify tuples of a relation , but cannot be qualified as a primary key are the alternate keys.(In the above example , Name can be alternate key as the names are unique)
Foreign Key
The attributes of a relation that reference the attributes of another relation are the foreign keys.
In the example above Person_ID is the foreign key. It references the primary key of person table (person_id of person table).
The table that references other table is the derived table . The table that is being referenced is the base table.
Foreign key attribute in the derived table should contain only the values that are in the attribute of the base table.
Foreign key need not be unique ( In the derived table , the foreign key values can also be repeated )
There can be any number of foreign keys in derived table.
This is all about the basics of the Relational Databases.
Thank You for reading.