1

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

4

1 回答 1

0

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'

Demo

The DDL and DML statements are mixed, which is violation, within your cases.

于 2020-03-16T15:48:15.847 回答