close[x]


MySQL

MySQL-Home MySQL-Environment setup MySQL- Workbench MySQL-Basic syntax MySQL-Operator MySQL-Data type MySQL-Comments MySQL-Create DB MySQL-Drop DB MySQL-Select DB MySQL-Create Table MySQL-Drop table MySQL-Truncate MySQL-Primary Key MySQL-Foreign Key MySQL-Null MySQL-Increment MySQL-Having MySQL-Top MySQL-Insert Statement MySQL-Select Statement MySQL-Alter Statement MySQL-Where MySQL-And & Or MySQL-Default values MySQL-Exists MySQL-Order by MySQL-View MySQL-Update Statement MySQL-Delete Statement MySQL-Like MySQL-Sort MySQL-Limit MySQL-Min MySQL-Max MySQL-Group MySQL-In MySQL-Between MySQL-Union MySQL-Count MySQL-Average MySQL-Sum MySQL-Date & Time MySQL-Import MySQL-Export MySQL-Index MySQL-Temporary MySQL-Join MySQL-Full Join MySQL-Inner Join MySQL-Left Join MySQL-Right Join MySQL-Store Procedure MySQL-Injection MySQL-PHP connection



learncodehere.com



MySQL - NOT NULL

The NOT NULL constraint enforces a column to NOT accept NULL values.

The NOT NULL constraint enforces a field to always contain a value.

You cannot insert a new record, or update a record without adding a value to this field.


Syntax : NOT NULL


CREATE TABLE table_name
 (
 column1 data_type(size) NOT NULL,
 column2 data_type(size) NOT NULL,
 column3 data_type(size) NOT NULL,
 ....
 );  

The following MySQL ensures that the "ROLL_NO" and "NAME" columns will NOT accept NULL values when the "Students" table is created:


Example : NOT NULL


 CREATE TABLE Students
 (
 ROLL_NO int(3) NOT NULL,
 NAME varchar(20) NOT NULL,
 SUBJECT varchar(20) ,
 );  

To create a NOT NULL constraint on the "SUBJECT" column when the "Students" table is already created, use the following SQL:


Example : NOT NULL


ALTER TABLE Students 
MODIFY SUBJECT SUBJECT varchar(20) NOT NULL;