What is Default constraint in SQL ?

  • Constraints are a certain set of rules used for processing data and limiting the type of data that can go into the table.
  • The default constraint is used to define a default value for a column so that the default value will be added to all new records if no other value is specified.
  • For example, if we set the default value to 85000 as a default constraint for the E_salary column, then all the other entries in the column will have a default constraint value of 85000 until no other values have been assigned for default constraint during insertion.

Syntax for setting a default constraint. Start by  creating a new table and adding a default constraint to one of its columns.

create table stu1(s_id int, s_name varchar(20), s_marks int default 50)
Leave a Reply

Your email address will not be published.

You May Also Like