MYSQL
- What are the differences between SQL and MySQL?
- What are the different data types in MySQL?
- Explain MySQL storage engines.
- What is the difference between MyISAM and InnoDB?
- What is a Primary key vs Foreign key
- What are constraints in MySQL?
- Explain the difference between CHAR and VARCHAR.
- What is normalization? Explain different normal forms.
- What is denormalization?
- What is the difference between WHERE and HAVING?
- Joins in mysql
- What is the difference between UNION and UNION ALL?
- What is a composite key?
- What is EXPLAIN in MySQL?
- MySQL Indexing & Performance: A Complete Guide
- What are aggregate functions? Give examples.
- What is COALESCE() function?
- Understanding Transactions in Databases: A Complete Guide
- What are different types of locks in MySQL?
- Stored Procedures and Triggers in MySQL: Complete Guide
- Difference between a trigger and stored procedure?
- Views in MySQL – A Complete Guide
- What are temporary tables?
- MySQL Replication: A Complete Guide
- Partitioning in MySQL: A Complete Guide
- Difference between MySQL and MariaDB?
- How to monitor MySQL performance?
- MySQL Event Scheduler – The Complete Guide
- Understanding ROW_FORMAT in InnoDB (MySQL)
- What Are Triggers in MySQL? A Complete Guide
- Understanding Partitioning in Databases: A Complete Guide
- Difference between horizontal and vertical partitioning?
- What is replication in MySQL?
- Difference between master-slave and master-master replication?
- What is referential integrity?
- Difference Between CHAR, VARCHAR, and TEXT in MySQL
- Difference between ENUM and SET.
- What is a cursor in MySQL?
- Difference between temporary and regular table?
- Understanding ACID Properties in Databases
- What is query caching?
- IN, OUT, and INOUT parameters mean in Stored Procedures (MySQL)
- Optimistic vs Pessimistic Locking in MySQL
- Deadlocks in MySQL – Causes, Detection & Prevention
- Phantom Reads, Dirty Reads & Non-Repeatable Reads Explained
- MySQL Date and Time Basic Questions
- Dynamic period queries in MySQL for last week, last month, this year, etc.
- 🔥 Real-World Scenario-Based Date-Time Questions in MySQL
- 🔥 Basic Date-Time Questions in MySQL
- 🔥 Medium Level Date-Time Questions in MySQL
- 🔥 Advanced Level Date-Time Questions in MySQL
What is a composite key?
A composite key in a database is a primary key that consists of two or more columns in a table. Instead of using a single column to uniquely identify a record, the combination of multiple columns together ensures uniqueness.
Key Points:
- Purpose: Ensures that each row in a table is unique when a single column is not sufficient.
- Composition: Made up of two or more attributes (columns).
- Uniqueness: The combination of all columns in the composite key must be unique for every row. Individually, the columns may contain duplicate values.
- Use case: Common in many-to-many relationship tables (junction tables).
Example:
Consider a table CourseEnrollment:
| student_id | course_id | enrollment_date |
|---|---|---|
| 1 | 101 | 2025-08-01 |
| 1 | 102 | 2025-08-02 |
| 2 | 101 | 2025-08-01 |
- Here, neither
student_idnorcourse_idalone can uniquely identify a row, because a student can enroll in multiple courses and a course can have multiple students. - Composite key:
(student_id, course_id)ensures each row is unique.
So, a composite key is all about uniqueness through combination, not a single column.
No comments yet! You be the first to comment.
