SQL server schema

  • Thread starter Thread starter John Sutor
  • Start date Start date
J

John Sutor

Does anyone know what objects to use to query a SQL database to get back
all of the tables and then be able to get information on the tables and
column information (name, datatype, max length etc...)
 
John said:
Does anyone know what objects to use to query a SQL database to get back
all of the tables and then be able to get information on the tables and
column information (name, datatype, max length etc...)

Each database contains a sysobjects and syscolumns system tables. With a
joins on a few other system tables you can get the information direct
from the database. E.g.

USE your_database
GO
SELECT tbl.name, col.name, typ.name, col.length, col.isnullable,
col.collation
FROM sysobjects tbl
INNER JOIN syscolumns col
ON tbl.id = col.id
INNER JOIN systypes typ
ON col.xtype = typ.xtype
WHERE tbl.xtype = 'u' and typ.name != 'sysname'
ORDER BY tbl.name, col.colorder
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top