SQL- default constraint

default constraint is an arithmetic function in SQL.It is used to default up the number of rows in a certain column of a table.


SYNTAX :
CREATE TABLE table_name
(column1 datatype DEFAULT default_value,
column2 datatype,
.....
);


1. Table_name -> is the name of table
2. column1,column2,... -> is the name of the columns.
3. datatype -> is the datatype of the column.
4. we define DEFAULT Integrity Constraint for column1
    then column1 cannot store NULL.

Syntax -> set DEFAULT constraint on ALTER TABLE

MySQL:

ALTER TABLE table_name
ALTER column_name SET DEFAULT default_value;



SQL Server / MS Access:

ALTER TABLE table_name
ALTER COLUMN column_name SET DEFAULT default_value;



Oracle:

ALTER TABLE table_name
MODIFY  column_name  DEFAULT default_value;



Syntax -> DROP DEFAULT constraint


MySQL:

ALTER TABLE table_name
ALTER column_name DROP DEFAULT;



SQL Server / Oracle / MS Access:
ALTER TABLE table_name
ALTER COLUMN column_name DROP DEFAULT;



Online Execute/Compile