Databases| SQL| MySQL| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Mysql Add Column Default Value 
 

Mysql Add Column Default Value is used to add the default value to the column. The records take a default value when there is no value for a records put inside the specified column of table.

 

Mysql Add Column Default Value

                         

Mysql Add Column Default Value is used to add the default value to the column. The records take a default value when there is no value for a records put  inside the specified column of table.

Understand with Example

The Tutorial illustrate an example from 'Mysql Add Column Default Value'. To understand and grasp this example we create a table 'stu' and 'lib' with required fieldnames and datatypes respectively.

 

 

 

Create Table Stu

Create Table Stu(Id int, Name varchar(10), Class  int);

Describe Stu

The Describe Stu is used to describe the fieldname,Type,Null ,etc in the table.

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Id    | int(11)     | YES  |     |         |       |
| Name  | varchar(10) | YES  |     |         |       |
| Class | int(11)     | YES  |     |         |       |
+-------+-------------+------+-----+---------+-------+

Query for  Add Column Default Value

The Query Alter is used to modify the table 'stu' and add a default value of 10 for those records which don't have value specified in a column.

ALTER TABLE Stu MODIFY class int Default '10';

Describe Stu

+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| Id    | int(11)     | YES  |     |         |       |
| Name  | varchar(15) | YES  |     |         |       |
| class | int(11)     | YES  |     | 10      |       |
+-------+-------------+------+-----+---------+-------+

Insert data into Stu

Insert Into Stu (Id, Name) values(1,'Komal');
Insert Into Stu (Id, Name) values(2,'Ajay');
Insert Into Stu (Id, Name) values(3,'Rakesh');
Insert Into Stu (Id, Name) values(4,'Bhanu');
Insert Into Stu (Id, Name) values(5,'Santosh');

Stu Table

+------+---------+-------+
| Id   | Name    | class |
+------+---------+-------+
| 1    | Komal   | 10    |
| 2    | Ajay    | 10    |
| 3    | Rakesh  | 10    |
| 4    | Bhanu   | 10    |
| 5    | Santosh | 10    |
+------+---------+-------+

                         

» View all related tutorials
Related Tags: php sql mysql c table data ui insert datatypes types type tutorial field name using ria create tab ie example

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.