Professional Documents
Culture Documents
RDBMS, Keys, Constraints
RDBMS, Keys, Constraints
RDBMS, Keys, Constraints
Tuples/Rows
RDBMS
Relations
• A relation is a two-dimensional table:
• Relation ≈ table.
• Attribute ≈ column name.
• Tuple ≈ row (not the header row).
• Database ≈ collection of relations.
• A relation has two parts:
• Schema defines column heads of the table (attributes).
• Instance contains the data rows (tuples, rows, or records) of the table.
CoursesTaken :
Student_name Course Grade
Hermione Grainger Potions A-
Draco Malfoy Potions B
Harry Potter Potions A
Ron Weasley Potions C
INSTRUCTOR(ID,name,dept_name,salray)
INSTRUCTOR
Customer
Customer
Customer
AGE
Customer
Cust_Name Cust_ID Gender DOB Door_no Phone_no
Keys
• A data item [attribute] which can uniquely identify a tuple in a relation.
✓ SUPER KEY
✓ CANDIDATE KEY
✓ PRIMARY KEY
SUPER KEY
• Any combination of attributes which can uniquely identify a tuple
s_name S_roll
ram 123
sanjay 124
manju 125
meenu 126
Super Key={S_roll} , {s_name,S_roll}
ram 127
Keys
Identify super keys for the following table
Book
book_id name author
B1 XYZ A1
B2 ABC A1
B3 XYZ A2
B4 PQR A3
B5 LSP A1
SK={ book_id} , {book_id,name}, {name,author}, {book_id,name,author}
Book
book_id name author
B1 XYZ A1
B2 ABC A1
B3 XYZ A2
B4 PQR A3
B5 LSP A1
Keys
SUPER KEY
CANDIDATE KEY
PRIMARY KEY
Department Employee
DeptCode DeptName Teacher ID Fname Lname
001 Science B002 David Warner
002 English B017 Sara Joseph
005 Computer B009 Mike Brunton
Employee
Teacher ID Fname Lname DeptCode
B002 David Warner 001
B017 Sara Joseph 002
B009 Mike Brunton 005
Department Employee
DeptCode DeptName Teacher ID Fname Lname
001 Science B002 David Warner
002 English B017 Sara Joseph
005 Computer B009 Mike Brunton
Employee
r1 – referencing relation
r2- referenced relation
Department Employee
DeptCode DeptName Teacher ID Fname Lname
001 Science B002 David Warner
002 English B017 Sara Joseph
005 Computer B009 Mike Brunton
Referenced Relation
Employee
✓ Domain constraints
✓ Entity integrity constraints
✓ Referential Integrity Constraints
✓ Key constraints
Integrity Constraints
Domain Constraints
• Domain constraints can be defined as the definition of a valid set of values for an attribute.
• The data type of domain includes string, character, integer, time, date, currency, etc. The
value of the attribute must be available in the corresponding domain.
Integrity Constraints
Entity Constraints
• The entity integrity constraint states that primary key value can't be null.
• This is because the primary key value is used to identify individual rows in
relation and if the primary key has a null value, then we can't identify those
rows.
• A table can contain a null value other than the primary key field.
Integrity Constraints
Referential Integrity Constraints
• Referential integrity refers to the accuracy and consistency of data within a relationship.
• In relationships, data is linked between two or more tables. (FK,PK)
• Need to ensure that data on both sides of the relationship remain intact.
So, referential integrity requires that, whenever a foreign key value is used it must reference
a valid, existing primary key in the parent table.
Integrity Constraints - Referential
Department
DeptCode DeptName
001 Science
002 English Delete
005 Computer
Referenced Relation
• Adding records to a related table if there is no associated record in the primary table.
• Changing values in a primary table that result in orphaned records in a related table.
• Deleting records from a primary table if there are matching related records.