获取表中没有默认值NULL的所有列名的列表? [英] Get list of all column names in a table that do not have NULL as their default value?

查看:71
本文介绍了获取表中没有默认值NULL的所有列名的列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取表中所有不具有NULL作为默认值的列名称的列表?

How do I get a list of all column names in a table that do not have NULL as their default value?

如果我执行从表名中显示栏",我看到结果中有一列称为默认".我希望我的语句仅返回那些没有NULL作为默认值的列.我曾尝试使用WHERE子句,但我认为它很令人讨厌,因为默认"是保留字.

If I do "SHOW COLUMNS FROM table_name", I see there is a column in the results called "Default". I'd like my statement to return ONLY those columns that do not have NULL as the Default. I've tried using a WHERE clause, but I think it chokes because "Default" is a reserved word.

感谢您的帮助!

推荐答案

您可以查询 INFORMATION_SCHEMA.COLUMNS 表:

SELECT * FROM INFORMATION_SCHEMA.COLUMNS
 WHERE table_name = 'my_table'
   AND column_default is [not] null;

您的标题说默认为空",而帖子说默认不为空".选择一个:-)

Your title says "have null as their default" but post say "do not have null as their default". Pick one :-)

这篇关于获取表中没有默认值NULL的所有列名的列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆