Questions
20 of 26
1What is a key in MySQL and why is it used?
2What is the difference between a key and an index?
3What is a primary key? Can a table have more than one primary key?
4What is a foreign key and why is it important in relational databases?
5How do you define a primary key when creating a table?
6Can a primary key column contain NULL values? Why or why not?
7What is the difference between a UNIQUE key and a PRIMARY key?
8What is an AUTO_INCREMENT key, and how does it work with the primary key?
9Can two tables have the same primary key name? Explain.
10What is the purpose of the FOREIGN KEY constraint in maintaining referential integrity?
11What is a composite key? How do you define one in MySQL?
12What are candidate keys, and how do they differ from alternate keys?
13What happens if you try to insert a duplicate value into a UNIQUE key column?
14How do foreign key constraints behave on DELETE and UPDATE operations (CASCADE, SET NULL, etc.)?
15What are the differences between ON DELETE CASCADE and ON DELETE SET NULL? What is a super key, and how does it relate to candidate keys? Can a foreign key reference a non-primary key column in another table?
16How do you disable and re-enable foreign key checks in MySQL? Why would you do that?
17How do you drop a primary key or foreign key from an existing table?
18How can you find all foreign key relationships in a MySQL database?
19How does InnoDB enforce foreign key constraints internally?
20What is the impact of defining multiple UNIQUE keys on the same table?
21Can you define a foreign key constraint referencing a table in a different database schema?
22Explain how key definitions affect indexing and query optimization.
23What are the differences between logical keys (like candidate or composite keys) and physical indexes?
24Can a composite key contain a foreign key as one of its columns? Provide an example.
25How does MySQL handle updates to parent keys that are referenced by foreign keys?
26What are deferred constraint checks, and does MySQL support them? How do you design keys in a many-to-many relationship using a junction (bridge) table? What are the potential performance implications of using multiple foreign keys and composite keys in large-scale systems?
20 / 26

What is the impact of defining multiple UNIQUE keys on the same table?

Impact of Defining Multiple UNIQUE Keys on a Table

A table in MySQL can have multiple UNIQUE keys, and each one enforces uniqueness on different columns or column combinations. This improves data integrity but also has performance and storage implications.

1. Ensures Multiple Sets of Values Are Unique
  1. 1

    Each UNIQUE key enforces its own independent uniqueness rule.

  2. 2

    Example: email must be unique AND username must be unique in the same table.

  3. 3

    This allows multiple business rules for avoiding duplicates.

2. Each UNIQUE Key Creates an Index
  1. 1

    Every UNIQUE constraint automatically creates a UNIQUE index.

  2. 2

    More indexes → more disk usage.

  3. 3

    More indexes → slower INSERT, UPDATE, DELETE operations because MySQL must update all related indexes.

3. Read Performance May Improve
  1. 1

    Queries filtering by unique columns use UNIQUE indexes, improving lookup speed.

  2. 2

    SELECT queries benefit from having more indexed columns to search with.

4. Composite UNIQUE Keys and Overlapping Columns
  1. 1

    Unique keys can be single-column or multi-column.

  2. 2

    Overlapping unique indexes (e.g., UNIQUE(a), UNIQUE(a,b)) increase storage and maintenance cost.

  3. 3

    MySQL does not automatically optimize or merge redundant unique indexes.

5. Can Affect Foreign Key Relationships
  1. 1

    A foreign key can reference any UNIQUE key (not only the primary key).

  2. 2

    Having multiple unique keys gives flexibility for relational design.

In summary, multiple UNIQUE keys improve data integrity and query performance but increase index maintenance overhead and storage usage.