mysql select into的变通方法

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mydb               |
| mysql              |
| performance_schema |
| test               |
+--------------------+
5 rows in set (0.01 sec)

mysql> use mydb
Database changed
mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| employee       |
+----------------+
1 row in set (0.01 sec)

mysql> desc employee
    -> ;
+--------+---------+------+-----+---------+-------+
| Field  | Type    | Null | Key | Default | Extra |
+--------+---------+------+-----+---------+-------+
| Id     | int(11) | NO   | PRI | NULL    |       |
| Salary | int(11) | YES  |     | NULL    |       |
+--------+---------+------+-----+---------+-------+
2 rows in set (0.05 sec)

mysql> SELECT * INTO employees FROM employee;
ERROR 1327 (42000): Undeclared variable: employees
mysql> CREATE TABLE employees(SELECT * FROM employee);
Query OK, 3 rows affected (0.02 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> show tables;
+----------------+
| Tables_in_mydb |
+----------------+
| employee       |
| employees      |
+----------------+
2 rows in set (0.00 sec)

mysql>

posted on 2020-11-25 09:47  shenggong  阅读(1172)  评论(0编辑  收藏  举报

导航