mysql – 可以将DESCRIBE语法嵌入到SELECT语句中吗?

MySQL中,DESCRIBE语法可以显示表的结构,但不能嵌入到正常语句中;有一些棘手的方法吗?

例如,这显示了table1结构,返回为一个表(但SQL语句不这么认为)

DESCRIBE `table1`

但这不行:

SELECT * FROM (DESCRIBE `table1`)

有没有办法启用它?

我想加入由DESCRIBE语法创建的“表”,我该怎么办?

您可以使用INFORMATION_SCHEMA的COLUMNS表获取预期结果作为DESCRIBE表选项的替代解决方案.

尝试这个:

SELECT COLUMN_NAME AS `Field`, COLUMN_TYPE AS `Type`, IS_NULLABLE AS `NULL`, 
       COLUMN_KEY AS `Key`, COLUMN_DEFAULT AS `Default`, EXTRA AS `Extra`
FROM information_schema.COLUMNS  
WHERE TABLE_SCHEMA = 'schemaName' AND TABLE_NAME = 'table1';
翻译自:https://stackoverflow.com/questions/20769255/can-describe-syntax-be-embedded-in-select-statement

转载注明原文:mysql – 可以将DESCRIBE语法嵌入到SELECT语句中吗?