Hi, I want to know which table's field are required or not required so I have to get "Allow nulls" state. How to do that?
views:
85answers:
3
+3
A:
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.
Kevin
2009-10-14 16:59:17
+1: I didn't knew about this view, ty
Rubens Farias
2009-10-14 17:05:10
A:
If your in MySQL use the sql command
DESCRIBE Table;
Where table is the name of the table you want to examine
Mohgeroth
2009-10-14 16:59:23
A:
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'
Rubens Farias
2009-10-14 17:04:02
As of SQL Server 2005, you should stop using "sysobjects" and start using the proper and more focused catalog views in the "sys" schema, e.g. "sys.tables", "sys.columns" and so forth
marc_s
2009-10-14 20:25:37