Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
SQL Alter Column Default Value 
 

Alter Column Default Value in SQL Server is used with Create Table Statement.

 

SQL Alter Column Default Value

                         

Alter Column Default Value in  SQL Server is used with Create Table Statement. The default value will be set as per specified column. The use of default value is specified when insert is performed, but value in the column is not set.

Understand with Example 

In this Tutorial, the query create a table 'Stu_Table' using a create statement. The insert into in SQL Query add the records to table. The Describe table show you the Table attribute like field, data type etc.

Create Table Stu_Table

create table Stu_Table( Stu_Id integer(2), Stu_Name varchar(15), 
Stu_Class  varchar(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        | 
+--------+----------+-----------+

Describe Stu_Table

+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| Stu_Id    | varchar(10) | YES  |     |         |       |
| Stu_Name  | varchar(10) | YES  |     | NULL    |       |
| Stu_Class | varchar(5)  | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+

Alter column Column Default Query

The Alter Table Keywords modify table'Stu_Table' and MODIFY keyword modify the data type of field Stu_Id (varchar(10)) to Stu_Id(int(3)) and set the default value for this field is set '10'.Whenever you leave a blank value in Stu_Id, This field would take default value of '10'.

ALTER TABLE Stu_Table MODIFY Stu_Id int(3) Default '10'

Describe Stu_Table

+-----------+--------------+------+-----+---------+-------+
| Field     | Type         | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+-------+
| Stu_Id    | int(3)       | No   |     |  10       |       |
| Stu_Name  | varchar(10)  | YES  |     | NULL    |       |
| Stu_Class | varchar(5)   | YES  |     | NULL     |       |
+-----------+--------------+------+-----+---------+-------+

                         

» View all related tutorials
Related Tags: sql mysql c string function fun io sed char return character unc cte to e use from left in m

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.