codescracker


sql

SQL Default



« Previous Tutorial Next Tutorial »


SQL DEFAULT constraint is used to insert the default value into a column in case if no value is specified.

SQL DEFAULT Constraint on CREATE TABLE

Here are the SQL Statements creates a DEFAULT constraint on the column "City" when the table "Students" is created:

For MySQL / SQL Server / Oracle / MS Access Databases

CREATE TABLE Students
(
P_ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Address varchar(255),
City varchar(255) DEFAULT 'Gurgaon'
)

SQL DEFAULT Constraint on ALTER TABLE

Here are the SQL statements used to create a DEFAULT constraint on the column "City" when the table is already created:

For MySQL Database

ALTER TABLE Students
ALTER City SET DEFAULT 'Gurgaon'

For SQL Server / MS Access Databases

ALTER TABLE Students
ALTER COLUMN City SET DEFAULT 'Gurgaon'

For Oracle Database

ALTER TABLE Students
MODIFY City DEFAULT 'Gurgaon'

DROP SQL DEFAULT Constraint

Here are the SQL statements used to drop SQL DEFAULT constraint:

For MySQL Database

ALTER TABLE Students
ALTER City DROP DEFAULT

For SQL Server / Oracle / MS Access Databases

ALTER TABLE Students
ALTER COLUMN City DROP DEFAULT

« Previous Tutorial Next Tutorial »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test