开发者

SQL: how to know if a field has "Allow nulls" checked or not checked by SQL command

开发者 https://www.devze.com 2022-12-09 01:15 出处:网络
I want to know which table\'s field are required or not required so I have to get \"Allow nulls\" stat开发者_JAVA百科e. How to do that?I will assume you are talking about SQL Server.

I want to know which table's field are required or not required so I have to get "Allow nulls" stat开发者_JAVA百科e. How to do that?


I will assume you are talking about SQL Server.

There is a table, INFORMATION_SCHEMA.COLUMNS, that contains meta-data about the columns in the database.

You can do this:

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, IS_NULLABLE
FROM INFORMATION_SCHEMA.COLUMNS
ORDER BY TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME

IS_NULLABLE gives you the "Allow Nulls" value used in the designer.


If your in MySQL use the sql command

DESCRIBE Table;

Where table is the name of the table you want to examine


Try this (SQL Server)

select sysobjects.name, syscolumns.name, syscolumns.isnullable
from   sysobjects join syscolumns
   on  sysobjects.id    = syscolumns.id
  and  sysobjects.xtype = 'U'
  and  sysobjects.name  = 'your table name'
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号