DEFAULT in SQL

HOW TO USE DEFAULT CONSTRAINT IN SQL?

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;


Posted

in

Tags:

Comments

Leave a Reply