docs没有提到ORDER BY,我没有运气这句话:
SHOW FIELDS FROM `TB_Main` WHERE Type = 'mediumtext' OR Type = 'bit(1)' ORDER BY Field;
我是否必须在编写脚本时进行订购?
答案 0 :(得分:1)
您可以直接查询信息架构表。正如manual says:
以下陈述几乎相同:
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'tbl_name' [AND table_schema = 'db_name'] [AND column_name LIKE 'wild'] SHOW COLUMNS FROM tbl_name [FROM db_name] [LIKE 'wild']
您可以将ORDER BY
子句应用于第一种语句,因为它是一个普通的SELECT
命令。
因此,您可以执行以下操作代替SHOW
命令:
SELECT COLUMN_NAME, DATA_TYPE, IS_NULLABLE, COLUMN_DEFAULT
FROM INFORMATION_SCHEMA.COLUMNS
WHERE
TABLE_NAME = 'TB_Main'
AND COLUMN_TYPE IN ('mediumtext', 'bit(1)')
ORDER BY COLUMN_NAME;