Search⌘ K

Answer: The NOT NULL Constraint

Explore how to apply the NOT NULL constraint in SQL to enforce mandatory data entry in table columns. Understand using ALTER TABLE to modify columns, adding default values, and alternative methods for imposing NOT NULL constraints to maintain data integrity.

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 Employees table. The MODIFY COLUMN modifies the column Salary column to be NOT NULL.

  • Line 10: DESC elaborates the ...