SQL add column default value

Add a Column default value is used in SQL, When create statement Query is performed in SQL .Usually, the default value is given to the column ,when no value is inserted to the column .

SQL add column default value

SQL add column default value

     

Add a Column default value is used in SQL, When create statement Query is performed in SQL .Usually, the default value is given to the column ,when no value is inserted to the column .

Understand with Example

The Tutorial understand you a example from SQL add column default value .In this, we create a table Stu_Table using create statement with field name Stu_Class. The '10' in a data type specification indicates a default value for a column. The insert into add the records into the table. The Stu_Class takes the default value of 10,when no value is inserted into table during insert statement operation.

Create Table Stu_Table

create table Stu_Table(Stu_Id integer(2), Stu_Name varchar(15), 
Stu_Class  varchar(10) default '10')

Insert data into Stu_Table

insert into Stu_Table (Stu_Id, Stu_Name) values(1,'Komal');
insert into Stu_Table (Stu_Id, Stu_Name) values(2,'Ajay');
insert into Stu_Table (Stu_Id, Stu_Name) values(3,'Rakesh');
insert into Stu_Table (Stu_Id, Stu_Name) values(4,'Bhanu');
insert into Stu_Table (Stu_Id, Stu_Name) values(5,'Santosh');

Stu_Table

Stu_Id Stu_Name Stu_Class
1 Komal 10
2 Ajay 10
3 Rakesh 10
4 Bhanu 10
5 Santosh 10