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';

更多相关文章

  1. 如何从MySQL DBs的不同表中提取create语句?
  2. mysql语法之case when then与列转行
  3. mysql查询一条工单时间需要10秒。优化sql语句得以解决。
  4. MySql SELECT 语句执行顺序
  5. MySQL 绿色版基本设置语句
  6. MySQL表格查询基本语句2
  7. MySQL DELETE语句和TRUNCATE TABLE语句的区别
  8. mysql添加外键语句
  9. Mysql语句 AND 和 OR 的运用

随机推荐

  1. Android(安卓)进程间通信的几种实现方式
  2. Android中的进程和线程
  3. Android(安卓)RotateAnimation详解
  4. ADT转AndroidStudio建议
  5. Android学习记录1
  6. Android(安卓)IPC入门——AIDL
  7. 『转』Android(安卓)多个UI库及组件资源
  8. android 通过Intent使用Bundle传递对象
  9. 【android开发记录片】2.基于Eclipse的JN
  10. Android模拟器环境中添加和删除apk应用程