Mysql Alter Tables


 

Mysql Alter Tables

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

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 |
+----------+---------+---------------------+		

Ads