Module 2 Part3
Module 2 Part3
PART 3
SYLLABUS
• Structure of Relational Databases - Integrity
Constraints, Synthesizing ER diagram to
relational schema
• Introduction to Relational Algebra - select,
project, cartesian product operations, join -
Equi-join, natural join. query examples,
• Introduction to Structured Query Language
(SQL), Data Definition Language (DDL), Table
definitions and operations – CREATE, DROP,
ALTER, INSERT, DELETE, UPDATE.
SQL
• SQL stands for Structured Query Language.
CHARACTER STRING
• CHAR(n)/CHARACTER(n), VARCHAR(n)/
CHARACTER VARYING(n)/ CHAR VARYING(n),
CLOB, etc.
BIT STRING
• BIT(n), BIT VARYING(n), BLOBetc.
BOOLEAN
• 3 values – true, false & unknown.
DATE
• 10 positions: YYYY-MM-DD
TIME
• 8 positions: HH:MM:SS
TIMESTAMP
• Includes both date and time fields.
Specifying Constraints in SQL
• Entity Integrity constraint
• NULL constraint
• DEFAULT constraint
• UNIQUE constraint
• CHECK constraint
Entity Integrity Constraint
• PRIMARY KEY
▫ Specifies one or more attributes that make up
the primary key of a relation.
▫ If a primary key has a single attribute, the clause
can follow the attribute directly
Dnumber INT PRIMARY KEY;
PRIMARY KEY (DNo, DLocation)
Referential Integrity Constraint
• FOREIGN KEY
▫ A referential integrity constraint can be violated
when tuples are inserted or deleted, or when a
foreign key or primary key attribute value is
modified.