Concept of Keys in DBMS
Concept of Keys in DBMS
• Example:
• Table: Students
• Columns: StudentID (Primary Key), FirstName,
LastName
• Example Entry: (1, 'John', 'Doe')
Foreign Key
• • Establishes a link between two tables.
• • Refers to the primary key in another table.
• Example:
• Table: Enrollments
• Columns: EnrollmentID, StudentID (Foreign
Key), CourseID (Foreign Key)
• References: StudentID from Students table,
CourseID from Courses table
Candidate Key
• • A minimal set of attributes that can uniquely
identify a record.
• • Every table can have multiple candidate
keys.
• Example:
• Table: Users
• Columns: UserID, Email, PhoneNumber
• Candidate Keys: Email, PhoneNumber
Super Key
• • A set of one or more attributes that can
uniquely identify a record.
• • May contain extra attributes not necessary
for unique identification.
• Example:
• Table: Students
• Columns: StudentID, FirstName, LastName
• Super Key: {StudentID, FirstName}, {StudentID,
Composite Key
• • A key that consists of two or more
attributes.
• • Uniquely identifies a record when combined.
• Example:
• Table: Enrollments
• Columns: EnrollmentID, CourseID, StudentID
• Composite Key: {CourseID, StudentID}
Alternate Key
• • Any candidate key that is not chosen as the
primary key.
• Example:
• Table: Users
• Columns: UserID (Primary Key), Email,
PhoneNumber
• Alternate Key: Email, PhoneNumber
Example Database Schema
• Diagram showing relationships using primary
and foreign keys.
• Example:
• Students Table: StudentID (Primary Key),
FirstName, LastName
• Courses Table: CourseID (Primary Key),
CourseName
• Enrollments Table: EnrollmentID, StudentID
(Foreign Key), CourseID (Foreign Key)
Summary of Keys
• • Recap of key types and their importance.
• • Emphasize the role of keys in maintaining
data integrity and relationships.
Questions?
• • Open the floor for questions.
• • Encourage discussion on specific key-related
queries.
References
• • List of textbooks, articles, or websites used
for the presentation content.