How to used Default constraint in sql

  • For instance, the SQL statement that follows adds four columns to the Employee table and creates a new one.
  • Since the SALARY column is set to $3000.00 in this scenario by default, if the INSERT INTO statement does not specify a value for this column,
  • the column will be set to $3000.00 by default.
CREATE TABLE Employee(
   EMPID   INT              NOT NULL,
   EMPNAME VARCHAR (20)     NOT NULL,
   ADDRESS  CHAR (25) ,
   SALARY   DECIMAL (18, 2) DEFAULT 3000.00,
   PRIMARY KEY (EMPID)
);
  • A query similar to the one shown in the code block below would be written to add a DEFAULT constraint to the SALARY field if the Employee table had previously been created.

Submit a Comment

Your email address will not be published. Required fields are marked *

Subscribe

Select Categories