|
首先,创建一个名为person_old的数据表,其表结构与person结构相同
mysql> CREATE TABLE person_old
-> (
-> id INT UNSIGNED NOT NULL AUTO_INCREMENT,
-> name CHAR(40) NOT NULL DEFAULT '',
-> age INT NOT NULL DEFAULT 0,
-> info CHAR(50) NULL,
-> PRIMARY KEY (id)
-> );
Query OK, 0 rows affected (0.11 sec)
向person_old表中添加两条记录
mysql> INSERT INTO person_old
-> VALUES (11,'Harry',20, 'student'), (12,'Beckham',31, 'police');
Query OK, 2 rows affected (0.20 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM person_old;
+----+---------+-----+---------+
| id | name | age | info |
+----+---------+-----+---------+
| 11 | Harry | 20 | student |
| 12 | Beckham | 31 | police |
+----+---------+-----+---------+
2 rows in set (0.00 sec)
插入数据到person表中
mysql> INSERT INTO person(id, name, age, info)
-> SELECT id, name, age, info FROM person_old;
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> SELECT * FROM person;
+----+---------+-----+------------+
| id | name | age | info |
+----+---------+-----+------------+
| 1 | Green | 21 | Lawyer |
| 2 | Suse | 22 | dancer |
| 3 | Willam | 20 | sports man |
| 4 | Laura | 25 | NULL |
| 5 | Evans | 27 | secretary |
| 6 | Dale | 22 | cook |
| 7 | Edison | 28 | singer |
| 9 | Harry | 21 | magician |
| 10 | Harriet | 19 | pianist |
| 11 | Harry | 20 | student |
| 12 | Beckham | 31 | police |
+----+---------+-----+------------+
11 rows in set (0.00 sec)
|
|
|