MySQL 
				- Introduction To MySQL
 - MySQL RDBMS
 - MySQL SQL
 - MySQL SELECT Statement
 - MySQL WHERE Clause
 - MySQL AND, OR And NOT Operators
 - MySQL ORDER BY Keyword
 - MySQL INSERT INTO Statement
 - MySQL NULL Values
 - MySQL UPDATE Statement
 - MySQL DELETE Statement
 - MySQL LIMIT Clause
 - MySQL MIN() And MAX() Functions
 - MySQL COUNT(), AVG() And SUM() Functions
 - MySQL LIKE Operator
 - MySQL Wildcards
 - MySQL IN Operator
 - MySQL BETWEEN
 - MySQL Aliases
 - MySQL Joins
 - MySQL INNER JOIN Keyword
 - MySQL LEFT JOIN Keyword
 - MySQL RIGHT JOIN Keyword
 - MySQL CROSS JOIN Keyword
 - MySQL Self Join
 - MySQL UNION Operator
 - MySQL GROUP BY Statement
 - MySQL HAVING Clause
 - MySQL EXISTS Operator
 - MySQL ANY And ALL Operators
 - MySQL INSERT INTO SELECT Statement
 - MySQL CASE Statement
 - MySQL NULL Functions
 - MySQL Comments
 - MySQL Operators
 - MySQL CREATE DATABASE Statement
 - MySQL DROP DATABASE Statement
 - MySQL CREATE TABLE Statement
 - MySQL DROP TABLE Statement
 - MySQL ALTER TABLE Statement
 - MySQL Constraints
 - MySQL NOT NULL Constraint
 - MySQL UNIQUE Constraint
 - MySQL PRIMARY KEY Constraint
 - MySQL FOREIGN KEY Constraint
 - MySQL CHECK Constraint
 - MySQL DEFAULT Constraint
 - MySQL CREATE INDEX Statement
 - MySQL AUTO INCREMENT Field
 - MySQL Working With Dates
 - MySQL Views
 - MySQL Data Types
 - MySQL Functions
 
MySQL DEFAULT Constraint
MySQL DEFAULT Constraint
The DEFAULT constraint is used to set a default value for a column.
The default value will be added to all new records, if no other value is specified.
Practice Excercise Practice now
DEFAULT On CREATE TABLE
The following SQL sets a DEFAULT value for the "City" column when the "Persons" table is created:
 
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
The DEFAULT constraint can also be used to insert system values, by using functions like CURRENT_DATE():
CREATE TABLE Orders (
ID int NOT NULL,
OrderNumber int NOT NULL,
OrderDate date DEFAULT CURRENT_DATE()
);
													ID int NOT NULL,
OrderNumber int NOT NULL,
OrderDate date DEFAULT CURRENT_DATE()
);
Practice Excercise Practice now
DEFAULT On ALTER TABLE
To create a DEFAULT constraint on the "City" column when the table is already created, use the following SQL:
 
ALTER TABLE Persons
ALTER City SET DEFAULT 'Sandnes';
													ALTER City SET DEFAULT 'Sandnes';
Practice Excercise Practice now
DROP A DEFAULT Constraint
To drop a DEFAULT constraint, use the following SQL:
 
ALTER TABLE Persons
ALTER City DROP DEFAULT;
													ALTER City DROP DEFAULT;
Practice Excercise Practice now
Products
Partner
Copyright © RVR Innovations LLP 2025 | All rights reserved - Mytat.co is the venture of RVR Innovations LLP