SQL DEFAULT Constraint

The SQL DEFAULT constraint is used to insert a default value into a column.
That means when no value is specified into a column then default value will be
inserted.

SQL DEFAULT Constraint on CREATE TABLE

The following SQL creates a DEFAULT constraint on the "Address" column when
the "Employee" table is created:
Oracle / SQL Server / MySQL / MS Access:
CREATE TABLE Employee
(
E_Idint NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255) DEFAULT 'BBSR'
)
The DEFAULT constraint can also be used to insert system values, by using functions like GETDATE():
CREATE TABLE Employee
(
E_Idint NOT NULL,
E_Nameint NOT NULL,
P_Idint,
SalaryDatedate DEFAULT GETDATE()
)

SQL DEFAULT Constraint on ALTER TABLE

To create a DEFAULT constraint on the "Address" column when the table is already created, use the following SQL:

Oracle:
ALTER TABLE Employee
MODIFY Address DEFAULT 'BBSR'
MySQL:
ALTER TABLE Employee
ALTER Address SET DEFAULT 'BBSR'

To DROP a DEFAULT Constraint

To drop a DEFAULT constraint, use the following SQL:
Oracle / SQL Server / MS Access:
ALTER TABLE Employee
ALTER COLUMN Address DROP DEFAULT
MySQL:
ALTER TABLE Employee
ALTER Address DROP DEFAULT



  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved