xxxxxxxxxx
Sets a default value for a column;
Example 1 (MySQL): Creates a new table called Products which has a
name column with a default value of ‘Placeholder Name’ and an available_
from column with a default value of today’s date.
CREATE TABLE products (
id int,
name varchar(255) DEFAULT 'Placeholder Name',
available_from date DEFAULT GETDATE()
);
Example 2 (MySQL): The same as above, but editing an existing table.
ALTER TABLE products
ALTER name SET DEFAULT 'Placeholder Name',
ALTER available_from SET DEFAULT GETDATE();
xxxxxxxxxx
CREATE TABLE Persons (
ID int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Age int,
City varchar(255) DEFAULT 'Sandnes'
);
xxxxxxxxxx
ALTER TABLE table_name
ALTER COLUMN column_name SET DEFAULT default_value;
xxxxxxxxxx
CREATE TABLE your_table (
column1 datatype DEFAULT default_value,
column2 datatype DEFAULT default_value
);
xxxxxxxxxx
SELECT COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'your_schema_name'
AND TABLE_NAME = 'your_table_name'
AND COLUMN_NAME = 'your_column_name';
xxxxxxxxxx
Are SQL attributes that have their default values even if the values are not provided