如何将一个表的列名存入另一个数据库表
如题
------解决方案--------------------
19.3. The INFORMATION_SCHEMA COLUMNS Table
The COLUMNS table provides information about columns in tables.
INFORMATION_SCHEMA Name SHOW Name Remarks
TABLE_CATALOG NULL
TABLE_SCHEMA
TABLE_NAME
COLUMN_NAME Field
ORDINAL_POSITION see notes
COLUMN_DEFAULT Default
IS_NULLABLE Null
DATA_TYPE Type
CHARACTER_MAXIMUM_LENGTH Type
CHARACTER_OCTET_LENGTH
NUMERIC_PRECISION Type
NUMERIC_SCALE Type
CHARACTER_SET_NAME
COLLATION_NAME Collation
COLUMN_TYPE Type MySQL extension
COLUMN_KEY Key MySQL extension
EXTRA Extra MySQL extension
PRIVILEGES Privileges MySQL extension
COLUMN_COMMENT Comment MySQL extension
------解决方案--------------------SQL code
create table 你的表1
select column_name from information_schema.columns where table_name = '你的表2';
insert into 你的表1
select column_name from information_schema.columns where table_name = '你的表xxx'
------解决方案--------------------
insert into dbname.tbname(a)
select column_name from information_schema.columns where table_name = '你的表2';