Search⌘ K
AI Features

Answer: The PRIMARY KEY Constraint

Explore the use of the PRIMARY KEY constraint in SQL, including how to add, modify, or remove it using ALTER TABLE. Understand the role of AUTO_INCREMENT and how these features help ensure data integrity while managing table structures.

Solution

The solution is given below:

MySQL
/* The query to modify the existing table's settings */
ALTER TABLE Employees
MODIFY EmpID INT AUTO_INCREMENT PRIMARY KEY;
/* Retrieve the structure of the table */
DESC Employees;

Explanation

The explanation of the solution code is given below:

  • Line 2: The ALTER TABLE query modifies a table. The MODIFY clause specifies which column to modify. The AUTO_INCREMENT sets the column to increase the number automatically when a new row is added. Finally, PRIMARY KEY sets the column to be NOT NULL, and it will be used as a primary key.

  • Line 5: The DESC ...