Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Concept of primary, foreign key, integrity constraints | RGPV DBMS PYQ

RGPV 2019
Q. Explain the concepts of Primary key, Foreign key and Integrity constraints ?

Ans.
If there is relation between table than it must have a primary key.
In table Student RollNo is primary key.

 

Student

 

RollNo

Name

Department

010

Sanjay

CSE

012

Ram Prasad

ME

021

Natwarlal

CSE

In table Account RollNo is primary key for it but also a Foreign key for table Student.

Account(Student)

RollNo

A/C No.

010

0074100

031

005452010

040

14540000

Primary keys cant contain duplicate value but, foreign keys can contain duplicate values.  
Also, Primary key cant contain NULL values, Foreign keys can contain NULL values.
Primary key vs Foreign key:

Primary Key

Foreign Key

No duplicate value.

Duplicate values allowed.

Null values not allowed.

Null values allowed.

Uniquely identified.

May be uniquely

It’s indexed automatically.

No automatic index.

A foreign key is a set of one or more columns in a table that refers to the “primary key in another table”. So foreign key Can’t contain a value which does not refer to the primary key, I am not agree that PhoneNumberTypeID is a foreign key.
Some integrity constraints are:
  1. Primary key constraints
  2. Foreign key constraints
  3. Unique key constraints
3. Unique key contraints:
A unique column constraint in a table is similar to a primary key in that the value in that column for every row of data in the table must have a unique value. Although a primary key constraint is placed on one column, you can place a unique constraint on another column even though it is not actually for use as the primary key.