MySQL Wildcards

MySQL Wildcards

MySQL Aliases

MySQL Aliases

MySQL Data Types

MySQL Data Types

MySQL Interview Questions

MySQL Interview Questions and Answers


MySQL NOT NULL Constraint

In MySQL, by default a column can hold NULL values, the NOT NULL constraint on the other hand restrict column to NOT to accept NULL values. The NOT NULL constraint forces the column to always accept a value. Using NOT NULL constraint you can make sure a column cannot have a NULL value.

MySQL NOT NULL Constraint example

The following MySQL, enforces column "custId", firstName", "lastName" and "address" to NOT to accept NULL values:

Example

CREATE TABLE tblCustomer (
    custId int NOT NULL,
    firstName varchar(255) NOT NULL,
    lastName varchar(255) NOT NULL,
    address varchar(255) NOT NULL
);

Note:

In the above example, we are creating new table called "tblCustomer" using NOT NULL constraint. The NOT NULL constraint enforces column "custId", firstName", "lastName" and "address" to NOT to accept NULL values.

You can use MySQL Command Line Client to enforces column to NOT to accept NULL values.