Make homepage|Add to favorites
 

MYSQL TOOLS
reviews, articles, tips & snippets

 
Buy SQL » MySQL » Copy data from one tabe to a new table

Copy data from one tabe to a new table

Author: rootsql Date: 1-11-2011, 22:20

Shows how to create new the same table and copy data.

CREATE TABLE table_a (
  id INT(11) DEFAULT NULL,
  column_a INT(11) DEFAULT NULL
);
INSERT INTO table_a VALUES 
  (1, 10),
  (2, 20),
  (3, 30),
  (4, NULL),
  (5, 0);

 

Create and copy data:

CREATE TABLE table_b SELECT * FROM table_a;

 

Check results:

SHOW CREATE TABLE table_b;
>
CREATE TABLE `table_b` (
  `id` int(11) DEFAULT NULL,
  `column_a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1

SELECT * FROM table_b;
+------+----------+
| id   | column_a |
+------+----------+
|    1 |       10 |
|    2 |       20 |
|    3 |       30 |
|    4 |     NULL |
|    5 |        0 |
+------+----------+

Tags: Tips

Dear visitor, you went to the site as unregistered user.
We recommend you to Register or Sign In.

Comments:

Leave a comment
Information
Members of Guests cannot leave comments.