可以在SELECT语句中嵌入描述语法吗?
16lz
2021-01-22
In MySQL, the syntax DESCRIBE
can show a table's structure, but it cannot be embedded to normal statement; is there some tricky way to do it?
在MySQL中,语法描述可以显示表的结构,但不能嵌入到普通语句中;有什么办法吗?
For example, this shows the table1
structure, returned as a table (but SQL statement does not think so)
例如,这显示了作为表返回的表1结构(但是SQL语句不这样认为)
DESCRIBE `table1`
But this doesn't work:
但这并不工作:
SELECT * FROM (DESCRIBE `table1`)
Is there a way to enable it?
是否有一种方法可以启用它?
I want to join the "table" created by DESCRIBE
syntax, how can I do it?
我想加入描述语法创建的“表”,我怎么做呢?
2 个解决方案
#1
17
You can use COLUMNS table of INFORMATION_SCHEMA to get expected result as an alternate solution of DESCRIBE table option.
您可以使用INFORMATION_SCHEMA的列表来获得预期结果,作为描述表选项的替代解决方案。
Try this:
试试这个:
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';
更多相关文章
- 如何从MySQL DBs的不同表中提取create语句?
- mysql语法之case when then与列转行
- mysql查询一条工单时间需要10秒。优化sql语句得以解决。
- MySql SELECT 语句执行顺序
- MySQL 绿色版基本设置语句
- MySQL表格查询基本语句2
- MySQL DELETE语句和TRUNCATE TABLE语句的区别
- mysql添加外键语句
- Mysql语句 AND 和 OR 的运用