SQL NULL, AUTO_INCREMENT & PRIMARY KEY()

NULL :- When a table contains two or more columns and we insert data into only one column then data in the second column will be automatically inserted as a NULL value.

NOT NULL & AUTO_INCREMENT:- When we want to make column auto-increment then it needs to be disabled its ‘NULL‘ feature. Write NOT NULL after the column’s data type.

After disabling NULL, the column value will be 0. It is an integer number. Hence we can set it on auto-increment mode. To do that, use AUTO_INCREMENT after disabling the null feature.

CREAT TABLE admission(
adm_no INT(10) NOT NULL AUTO_INCREMENT
);

PRIMARY KEY() – Now, you need to make this column as a primary key so that auto-increment mode can work on this column. Give column name in the parenthesis, you want to make as primary.

CREAT TABLE admission(
adm_no INT(10) NOT NULL AUTO_INCREMENT
PRIMARY KEY(adm_no)
);

Leave a Comment