Database Keys With Examples Presentation (1)
Database Keys With Examples Presentation (1)
• Example:
• Table: Students
• Columns: Student_ID (Primary Key), Name,
Age
• | Student_ID | Name | Age |
• |------------|------------|-----|
Foreign Key
• • A key in one table that refers to the Primary
Key of another table.
• • Ensures referential integrity.
• Example:
• Table: Orders
• Columns: Order_ID, Product_ID, Customer_ID
(Foreign Key referencing Customers table)
Candidate Key
• • A set of attributes that can uniquely identify
rows in a table.
• • A table can have multiple candidate keys,
one of which becomes the Primary Key.
• Example:
• Table: Employees
• Columns: Employee_ID, Passport_Number,
Email
Composite Key
• • A key composed of two or more columns to
uniquely identify rows in a table.
• Example:
• Table: Enrollments
• Columns: Student_ID, Course_ID
• Composite Key: (Student_ID, Course_ID)
• | Student_ID | Course_ID |
• |------------|-----------|
Unique Key
• • Ensures all values in a column are unique.
• • Allows one NULL value (unlike the Primary
Key).
• Example:
• Table: Users
• Columns: User_ID (Primary Key), Email
(Unique Key)
• | User_ID | Email |
Super Key
• • A set of attributes that can uniquely identify
rows in a table.
• • Includes Primary Key and additional
attributes.
• Example:
• Table: Books
• Columns: ISBN (Primary Key), Title, Author
• Super Key: (ISBN), (ISBN, Title), (ISBN, Author)
Conclusion
• • Keys are crucial for maintaining data
integrity and relationships.
• • Understanding different types of keys helps
in database design.
• • Practice with real-world examples to master
these concepts.