Search⌘ K
AI Features

Answer: The NOT NULL Constraint

Understand how to use the NOT NULL constraint in SQL by altering existing tables to enforce mandatory fields. Explore techniques to add or remove NOT NULL constraints, apply default values, and create temporary tables for multiple modifications. This lesson equips you with practical skills to manage SQL constraints effectively.

Solution

The solution is given below:

MySQL
/* Modifying the column EmpName to be NOT NULL */
ALTER TABLE Employees
MODIFY COLUMN EmpName VARCHAR (100) NOT NULL;
/* Modifying the column Salary to be NOT NULL */
ALTER TABLE Employees
MODIFY COLUMN Salary DECIMAL (10,2) NOT NULL;
/* Describe the structure of the table */
DESC Employees;

Explanation

The explanation of the solution code is given below:

  • Lines 2–3: The ALTER TABLE make changes to an already existing Employees table. The MODIFY COLUMN modifies the column EmpName column to be NOT NULL.

  • Lines 6–7: The ALTER TABLE make changes to an already existing  ...