SQL DEFAULT Constraint

The DEFAULT constraint is used to provides a default value to a column.

The default value will be added to all new entered records If new records are not specified the value.

EXAMPLE: DEFAULT Constraint

Create a SQL new table 'EMPLOYEE' and adds Six columns like [EMPLOYEE_ID, NAME, EMAIL, ADDRESS, AGE, and SALARY]. Set the SALARY column is 10,000 by default, so if the INSERT INTO statement does not provide a value for SALARY column, then by default the SALARY column would be set to 10,000. For example the SQL DEFAULT query mentioned below:

CREATE TABLE EMPLOYEE (
  EMPLOYEE_ID INT   NOT NULL,
  NAME VARCHAR (100)   NOT NULL,
  EMAIL VARCHAR (100),
  ADDRESS CHAR (200),
  AGE INT   NOT NULL,
  SALARY DECIMAL (100, 3) DEFAULT 10000,
  PRIMARY KEY(EMPLOYEE_ID)
);

ALTER TABLE - DEFAULT Constraint

ALTER TABLE EMPLOYEE
MODIFY SALARY DEFAULT 10000;

DROP DEFAUL Constraint

To drop a DEFAUL constraint, use the following SQL commond:

ALTER TABLE EMPLOYEE
ALTER COLUMN SALARY DROP DEFAULT;

Policy

GDATAMART.COM is optimized for learning & job information; The users try to improve your knowledge and practical experience through this site but we cannot warrant full correctness of all content... Learn More → | Sitemap →

© 2020 GDATAMART | All Rights Reserved