当前位置:   article > 正文

MySQL-将查询到的sql导入一张新表(新表未创建)_mysql将查询结果放入未建表

mysql将查询结果放入未建表

 

 语法:

create table ex_table_A  select * from table_A;

ex_table_A    是新创建的表的表名

  1. [root@localhost ~]# mysql -uroot -p
  2. Enter password:
  3. Welcome to the MySQL monitor. Commands end with ; or \g.
  4. Your MySQL connection id is 2
  5. Server version: 5.7.35 MySQL Community Server (GPL)
  6. Copyright (c) 2000, 2021, Oracle and/or its affiliates.
  7. Oracle is a registered trademark of Oracle Corporation and/or its
  8. affiliates. Other names may be trademarks of their respective
  9. owners.
  10. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
  11. mysql> show database;
  12. ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'database' at line 1
  13. mysql> show databases;
  14. +--------------------+
  15. | Database |
  16. +--------------------+
  17. | information_schema |
  18. | chen |
  19. | mysql |
  20. | performance_schema |
  21. | sys |
  22. +--------------------+
  23. 5 rows in set (0.10 sec)
  24. mysql> use chen;
  25. Reading table information for completion of table and column names
  26. You can turn off this feature to get a quicker startup with -A
  27. Database changed
  28. mysql> show tables;
  29. +----------------+
  30. | Tables_in_chen |
  31. +----------------+
  32. | stu |
  33. | stu_1 |
  34. | t_emp |
  35. +----------------+
  36. 3 rows in set (0.00 sec)
  37. mysql> select * from stu
  38. -> ;
  39. +----+------+
  40. | id | name |
  41. +----+------+
  42. | 1 | NULL |
  43. | 2 | lisi |
  44. | 3 | NULL |
  45. +----+------+
  46. 3 rows in set (0.03 sec)
  47. mysql> create table ex_stu select *from stu;
  48. Query OK, 3 rows affected (0.22 sec)
  49. Records: 3 Duplicates: 0 Warnings: 0
  50. mysql> show tables;
  51. +----------------+
  52. | Tables_in_chen |
  53. +----------------+
  54. | ex_stu |
  55. | stu |
  56. | stu_1 |
  57. | t_emp |
  58. +----------------+
  59. 4 rows in set (0.00 sec)
  60. mysql> select * from ex_stu;
  61. +----+------+
  62. | id | name |
  63. +----+------+
  64. | 1 | NULL |
  65. | 2 | lisi |
  66. | 3 | NULL |
  67. +----+------+
  68. 3 rows in set (0.00 sec)
  69. mysql>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/508891
推荐阅读
相关标签
  

闽ICP备14008679号