In this section, you will learn to copy one table to another in a same MySQL database.
This program helps you in copying one table to another in a same MySQL database. To copy any table, firstly, you need to establish the connection with MySQL database (jdbc4). This database has both the tables (Copyemployee and employee table). That is the one which is to be copied to the other table and the second is the table to be copied. For copying a table, we have applied the ?INSERT INTO Copyemployee SELECT * FROM employee? SQL statement. Whenever a table is copied, it displays ?Numbers of row(s) affected?. If none of the rows is copied then it shows a message ?Don?t add any row!?.
[Note: Both tables have the same field and its data type.]
for copy tables:
INSERT INTO <new_table_name> SELECT * FROM <old_table_name>
Here is code of program:
Table Name: employee
Table Name: Copyemployee
Output of this program:
Copy data from one table to another in a database!
After copy table: Copyemployee
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: July 6, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles