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
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.