The DEFAULT constraint in SQL is used to set a default value for a column.
Example of DEFAULT constraint creation in SQL server-
CREATE TABLE Students (
ID INT NOT NULL UNIQUE,
FirstName VARCHAR(200),
Fees INT,
City VARCHAR(200) DEFAULT โDelhiโ
);
Example to create DEFAULT constraint on existing table in SQL server-
ALTER TABLE Students
ADD CONSTRAINT d_city DEFAULT โDelhiโ FOR City;
Example to DROP a UNIQUE constraint in SQL server โ
ALTER TABLE Students
ALTER COLUMN City DROP DEFAULT;
Leave a Reply