Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (55.6k points)

Can anyone tell me how to make a column not null in SQL?

1 Answer

0 votes
by (119k points)

In SQL, A column in the table can have null values by default. We can use the NOT NULL constraint to not allow the user to enter null values in that particular column. In the following query, we cannot enter null values to the ‘ID’, ‘First_Name’, ‘Last_Name’ columns since not null constraint is specified for those columns:

CREATE TABLE Employee (
    ID                 int                 NOT NULL,
    Last_Name varchar(255) NOT NULL,
    First_Name varchar(255) NOT NULL,
    Age int
);

You can the following ALTER statement to add NOT NULL constraint to columns of an existing table:

ALTER TABLE Persons
MODIFY Age int NOT

You can go through SQL tutorial by Intellipaat to learn more NOT NULL constraint and other key constraints.

Browse Categories

...