Home Tutorial Php Sql Mysql Alter Tables

 
 

Share on Google+Share on Google+
Mysql Alter Tables
Posted on: December 9, 2010 at 12:00 AM
Advertisement
This example illustrates how to alert the table and how it is used in query.

Mysql Alter Tables

This example illustrates how to alert the table and how it is used in query.

In this example you will see all tables in test database by "show tabels" query. We create a query "ALTER TABLE tutorial RENAME example" which is used to alter table tutorial rename by example.

 

Query
show tables;
Output

 

+----------------+
| Tables_in_test |
+----------------+
| emp            |
| emp_counter    |
| emp_table      |
| employee       |
| message        |
| pictures       |
| testimage      |
| tutorial       |
| user           |
| users          |
+----------------+

Here we rename the table tutorial.

Query
ALTER TABLE tutorial RENAME example;
Output

 

+----------------+
| Tables_in_test |
+----------------+
| emp            |
| emp_counter    |
| emp_table      |
| employee       |
| example        |
| message        |
| pictures       |
| testimage      |
| user           |
| users          |
+----------------+

This query is used to execute renamed table example.

Query
 select * from example;
Output
+----------+---------+
| t_author | t_count |
+----------+---------+
| sandeep  | 20      |
| suman    | NULL    |
| kumar    | NULL    |
| mukesh   | 20      |
+----------+---------+

We can also alter table by adding column modified.

Query
ALTER TABLE example ADD COLUMN modified TIMESTAMP;
Output

 

+----------+---------+---------------------+
| t_author | t_count | modified            |
+----------+---------+---------------------+
| sandeep  | 20      | 0000-00-00 00:00:00 |
| suman    | NULL    | 0000-00-00 00:00:00 |
| kumar    | NULL    | 0000-00-00 00:00:00 |
| mukesh   | 20      | 0000-00-00 00:00:00 |
+----------+---------+---------------------+		
Advertisement

Related Tags for Mysql Alter Tables:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com