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
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.