Search
 
SCRIPT & CODE EXAMPLE
 

SQL

adding a default constraint to an existing column in sql

--Altering an existing column to add a default constraint:
ALTER TABLE {TABLE NAME}
ADD CONSTRAINT {CONSTRAINT NAME}
DEFAULT {DEFAULT VALUE} FOR {EXISTING COLUMN NAME}

--Adding a new column, with default value, to an existing table:
ALTER TABLE {TABLE NAME}
ADD {COLUMN NAME} {DATA TYPE} {NULL | NOT NULL}
CONSTRAINT {CONSTRAINT NAME} DEFAULT {DEFAULT VALUE}

--Dropping a contraint:
ALTER TABLE {TABLE NAME}
DROP CONSTRAINT {CONSTRAINT NAME}
Comment

SQL DEFAULT Constraint With Alter Table

#SQL Server

ALTER TABLE College
ADD CONSTRAINT country_default
DEFAULT 'US' FOR college_country;

#PostgreSQL

ALTER TABLE College
ALTER COLUMN college_code SET DEFAULT 'US';

#MySQL

ALTER TABLE College
ALTER college_country SET DEFAULT 'US';

#Oracle

ALTER TABLE College
MODIFY college_country DEFAULT 'US';
Comment

PREVIOUS NEXT
Code Example
Sql :: how to copy a table from one database to another in mysql 
Sql :: find last instance of character in string mysql 
Sql :: search for tables with name postgresql 
Sql :: sql count duplicate rows 
Sql :: oracle compile whole schema 
Sql :: ORA-01950 
Sql :: psql list rules 
Sql :: MySql get fields of table 
Sql :: postgres extract number from string 
Sql :: connect python to mysql 
Sql :: mysql date greater than 30 days 
Sql :: Error Code: 1055. Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 
Sql :: Starting mysql shell lampp ubuntu 
Sql :: postgresql format date dd/mm/yyyy 
Sql :: oracle list tables 
Sql :: mysql date between two dates 
Sql :: cross schema query oracle 2 users 
Sql :: check message id sql server 
Sql :: nvl postgres 
Sql :: oracle source query 
Sql :: oracle set date format 
Sql :: delete all rows from table mysql 
Sql :: sql server roles and users 
Sql :: sqlfiddle example tables 
Sql :: sql random decimal 
Sql :: base nosql 
Sql :: How Not To Sort By Average Rating 
Sql :: find nth highest salary of an employee 
Sql :: sql select only time from datetime 
Sql :: Database "mem:testdb" not found, either pre-create it or allow remote database creation (not recommended in secure environments) [90149-200] 90149/90149 (Help) 
ADD CONTENT
Topic
Content
Source link
Name
1+2 =