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.
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.
In my previous articles i have given the hierarchy of production support in real company…
In this article i would like to provide information about production support organization structure or…
In my previous article I have given roles for L1 and L2 support engineer with…
I have started this new series of how to become application support engineer. This article…
In this series we are starting with Roles and responsibilities of L1 support engineer .…
Introduction Cryptocurrencies took the world by storm, setting up a new financial system and breaking…