mysql - mysql - how to save results from DESCRIBE table into table
问题描述
I'm trying to implement the following code but doesn't seem to work in mysql:
insert into table2
DESCRIBE table1;
or
insert into table2
SHOW COLUMNS FROM table1;
any help is appreciated.
regards
解决方案
You can use such a way through use of information_schema.columns
:
CREATE TABLE table2(colname varchar(100), coltype varchar(100));
CREATE TABLE table1(col1 varchar(100), col2 int);
INSERT INTO table2
SELECT column_name, data_type
FROM information_schema.columns
WHERE table_name = 'table1'
The DDL and DML statements are mixed, which is violation, within your cases.
推荐阅读
- xamarin - 我需要在 XamarinForms 上的日期选择器中阻止粘贴功能
- terraform - Terraform template_file vars 属性得到定义
- java - Spring Cloud Stream 的 OUTPUT 通道的并发(线程执行器)
- python - Subprocess.call 未正确将命令传递到命令行
- javascript - 如何使函数仅与每个克隆的 div 单独运行而不与原始 div 一起运行
- python - Python中时间间隔的itertools.groupby问题
- big-o - 函数示例的 Big-O
- c# - 调用 Microsoft.Azure.CognitiveServices.Vision.Face.FaceClient.DetectWithStreamAsync 返回“操作返回了无效的状态代码‘NotFound’”
- json - 创建一个 json 路径表达式以获取所有特定的子元素,不包括第一个父元素
- jwt - 无法使用 Boxr gem Ruby SDK for Box API 通过 id 获取文件夹