H I O X INDIA
MySQL Tutorial
Google
Web hscripts.com
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Mysql Tutorial
Introduction
How to Install
Database
Datatypes
Tables
INSERT
SELECT
UPDATE
DELETE
Operators
Functions
Ask Your Doubts
Feedback





ALTER Table


Topic

Altering tables.
How to rename a table using ALTER?
How to add a column to a table?



Explanation


ALTER TABLE :

    ALTER TABLE is used to change the structure of an existing table. We can add or delete columns, change the type of existing columns, or rename columns or the table itself. We can also change the comment for the table and type of the table.

The Syntax is

ALTER TABLE tbl_name alter_specification [, alter_specification] ...

    The below table will describe the alter specification :

Alter SpecificationDescription
RenameRename a Table name
AddAdd a new column, key, index
Add FirstAdd a column First
Add AfterAdd a column After
DropDrop a column, Index, key
ChangeChange a column name
Change TypeChange a column type
ModifyModify a column type


Renaming a Table :

    We can also RENAME the table using ALTER TABLE. The following example query renames the table student to class.

mysql> ALTER TABLE student RENAME class;

    The above query will change the table name.

Adding a column to a table :

    The ADD COLUMN modifier is used to add a column to a table. The following example query adds a field called marks to the student table.

mysql> ALTER TABLE student ADD COLUMN marks INT(10);
Query OK, 0 rows affected (0.05 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> desc student;
+---------+-------------+------+-----+---------+-------+
| Field   | Type        | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| studid  | int(10)     | YES  |     | NULL    |       |
| name    | varchar(20) | YES  |     | NULL    |       |
| address | varchar(40) | YES  |     | NULL    |       |
| phone   | int(10)     | YES  |     | NULL    |       |
| marks   | int(10)     | YES  |     | NULL    |       |
+---------+-------------+------+-----+---------+-------+
5 rows in set (0.00 sec)
    Next we move to the alterations in displaying the tables.




others


        MySQL is the most popular open source database Management system. Being a open source anyone can use and change the software for their needs. Hope you enjoy this tutorial. We welcome your Valuable feedbacks or suggestions on this MySQL tutorial. This is a copyright content.


privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links