SQL – getting table info
Sometimes I’ve had the need to use SQL to go and get table information i.e is a field varchar or int etc.
For MS SQL server you can use the following to get info on a table
SELECT RIGHT(syscolumns.name, LEN(syscolumns.name)) AS dbFieldName, systypes.name AS typename, syscolumns.length AS maxlength, syscolumns.xprec AS [precision], syscolumns.xscale AS scale, syscolumns.isnullable AS isnullable
FROM syscolumns INNER JOIN
sysobjects ON sysobjects.id = syscolumns.id INNER JOIN
systypes ON syscolumns.xtype = systypes.xtype
WHERE (sysobjects.name = THE_TABLE_NAME)
ORDER BY syscolumns.colorder
Related posts:
- SQL – The case for CASE The Transact SQL Case statement is a particularly useful piece...























Recent Comments