Categories: SQL Tutorials

What are SQL Default Constraint with examples?

SQL Default Constraint :

In my previous articles i have explained about the different constraints in SQL.This article gives you idea about one of the important constraint of SQL which is SQL Default Constraint with real industry examples.This constraint is different from all other constraints.There are lot of times user needs to add the default value to the specific column of the table.Its really difficult to all default values to the column. In spite of that user can directly set the default value as a SQL Default Constraint so that user will not face any difficulty in inserting or updating the default values.SQL Default Constraint is basically used to insert default value.

‘SQL Constraints’ means rules and regulations to normalize the data

The following section gives user the idea about SQL Default Constraint with real industry examples.It helps the user to understand the concept of SQL Default Constraint with examples.

How to add SQL Default Constraints?

The DEFAULT constraint is used to insert a default value into a column.

The default value will be added to all new records, if no other value is specified.

The following SQL creates a DEFAULT constraint on the “Class” column when the “Student” Table is created:

CREATE TABLE Student

(

RollNo Number (10),

Subject Varchar2 (15),

Fees Number (10),

Class Number (5) DEFAULT 5,

DOJ Date Default SYSDATE

);

INSERT INTO Student (RollNo, Subject, Fees)

Values (105, ‘Sci’, 5000);

To DROP a DEFAULT SQL Constraints:

Note: To DROP a Default constraint you need to make is as NOT NULL first, then apply DROP Command.

ALTER TABLE Student MODIFY Class NOT NULL;

Syntax:

 

ALTER TABLE <Table_Name>

DROP CONSTRAINT <Constraint_Name>;

Example:

ALTER TABLE Student

DROP Constraint SYS_C005844;

SQL DEFAULT SQL Constraint on ALTER TABLE:

To create a DEFAULT constraint on the “Subject” column when the table is already created, use the following SQL:

Example:

ALTER TABLE Student

MODIFY Subject DEFAULT ‘English’;

Hope You Like this article on SQL Default Constraint with real industry example.This article will help user to understand the concept of SQL Default Constraints with different examples.If you like this article or if you have any suggestions for this article kindly comment it on comment section.

Amit S

Oracle Consultant with vast experience in Oracle BI and PL/SQL Development. Amiet is the admin head of this website who contributes by preparing tutorials and articles related to database technologies. He is responsible to manage the content and front-end of the website.

Recent Posts

What is Root Cause Analysis (RCA) With real examples

In my previous article I have given details about application support engineer day to day…

4 weeks ago

Application Support Engineer Day to day responsibilities

In my previous articles I have given the roles and responsibilities of L1,L2 and L3…

1 month ago

What is mean by SLA ( Service Level Agreement) with Examples?

In my previous articles i have given the hierarchy of production support in real company…

1 month ago

What is Production support Hierarchy in organization?

In this article i would like to provide information about production support organization structure or…

1 month ago

What are roles and responsibilities for L3 Support Engineer?

In my previous article I have given roles for L1 and L2 support engineer with…

1 month ago

What are roles and responsibilities of L2 Engineer?

I have started this new series of how to become application support engineer. This article…

1 month ago