Search⌘ K
AI Features

Answer: The PRIMARY KEY Constraint

Explore how to manage the PRIMARY KEY constraint in SQL. Learn to add, modify, and remove PRIMARY KEYs using ALTER TABLE and understand the importance of AUTO_INCREMENT in key management. Gain practical skills for interview questions on SQL constraints.

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 ...