RDBMS Basics
RDBMS Basics
DATABASE
DEPARTMENT
DEPTNO DNAME LOCATION
10 HR NEW YORK
20 ACCOUNTS BRAZIL
30 SALES CANADA
40 IT INDIA
COMPONENTS OF A TABLE
1) Degree of Table
2) Cardinality of Table
3) Attributes of Table
4) Tuple
5) Data types of Book Code and Price
CONCEPT OF KEYS
In relation each record must be unique i.e. no two identical records are
allowed in the Database. A key attribute identifies the record and must have
unique values. There are various types of Keys:
Primary Key, Candidate Key, Alternate Key and Foreign Key.
Primary Key
❖ A set of one or more attribute that can identify a record uniquely in the relation is
called Primary Key.
❖ There can be only 1 primary key in a table
❖ Allows only distinct (no duplicate) values and also forces mandatory entry (NOT
NULL) i.e. we cannot left it blank.
Candidate Key
❖ In a table there can be more than one attribute which contains unique values. These
columns are known as candidate key as they are the candidate for primary key.
❖ Among these database analyst select one as a primary key based on requirement like
must contain unique value, compulsory entry and where maximum searching is done
etc.
Alternate Key
❖ In case of multiple candidate keys, one of them will be selected as Primary Key
and rest of the column will serve as Alternate Key
❖ A Candidate Key which is not a primary key is an Alternate Key.
Foreign key
❖ Used to create relationship between two tables.
❖ It is a non-key attribute whose value is derived from the Primary key of another
table.
❖ Foreign key column will for the value in Primary key of another table, if present
then entry will be allowed otherwise data will be rejected.
❖ Primary Key column table from where values will be derived is known as Primary
Table or Master Table or Parent Table and Foreign key column table will be
Foreign Table or Detail Table or Child table
EMPLOYEE
EMPNO ENAME GENDER DEPTNO SALARY COMM
Child
1 ANKITA F 10 20000 1200 Table
2 SUJEET M 20 24000
3 VIJAYA F 10 28000 2000
4 NITIN M 30 18000 3000
5 VIKRAM M 30 22000 1700
DEPARTMENT
Parent
DEPTNO DNAME LOCATION
Table
10 HR NEW YORK
20 ACCOUNTS BRAZIL
30 SALES CANADA
40 IT INDIA
From the Above table definition we can observe that the DEPTNO column of EMPLOYEE
table is deriving its value from DEPTNO of table DEPARTMENT. So we can say that the
DEPTNO of EMPLOYEE table is a foreign key whose value is dependent upon the Primary
key column DEPTNO of table DEPARTMENT.