Copy or backup table using mysql or sql query

Some time when you need to genrate a duplicate copy of a table by a single query then here is a simple query to fulfill your requirement.

Query :

create table table_name as select * from source_table


Example :  Take the below example table 
Table_name : tbl_user
+-----+--------+---------------+
| id  | name    |      salery |
+-----+--------+---------------+
| 301 | salman  |       16000 |
| 302 | shahrukh|       10000 |
| 303 | amir    |        8000 |
+-----+--------+---------------+

Now i want to create a backup or copy of the above tbl_user table with name tbl_user_bkup.So query is like below :



Query :
create table tbl_user_bkup as select * from tbl_user
 Output :
Table_name : tbl_user_bkup
+-----+--------+---------------+
| id  | name    |      salery |
+-----+--------+---------------+
| 301 | salman  |       16000 |
| 302 | shahrukh|       10000 |
| 303 | amir    |        8000 |
+-----+--------+---------------+
If you like this post please don't forgot to post a comment.
 
Happy coding Guys :)
 


Post a Comment

Previous Post Next Post