- SQL Basics
- SQL Home
- SQL Syntax
- SQL RDBMS
- SQL Databases
- SQL Data Types
- SQL Operators
- SQL Expressions
- SQL Database
- SQL Create Database
- SQL Select Database
- SQL Drop Database
- SQL Table
- SQL Create Table
- SQL Drop Table
- SQL Keywords
- SQL Insert Into
- SQL Select
- SQL Where
- SQL And & Or
- SQL Update
- SQL Delete
- SQL Like
- SQL Select Top
- SQL Group By
- SQL Order By
- SQL Distinct
- SQL In
- SQL Between
- SQL Joins
- SQL Joins
- SQL Inner Join
- SQL Left Join
- SQL Right Join
- SQL Full Join
- SQL Constraints
- SQL Constraints
- SQL Unique
- SQL Not Null
- SQL Primary Key
- SQL Foreign Key
- SQL Check
- SQL Default
- SQL Create Index
- SQL Advance
- SQL Aliases
- SQL Union
- SQL Auto Increment
- SQL Views
- SQL Dates
- SQL Transactions
- SQL Injection
- SQL Test
- SQL Online Test
- Give Online Test
- All Test List
SQL Default
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 »
Like/Share Us on Facebook 😋