Find out table design

  • Thread starter Thread starter Alberto
  • Start date Start date
A

Alberto

How can I find out the design of a sql server 2005 table from a C# code? I'd
like to know the type and the lenght of the columns of some tables.

Thank you.
 
Alberto said:
How can I find out the design of a sql server 2005 table from a C# code?
I'd like to know the type and the lenght of the columns of some tables.
The simplest way is to use a DataAdapter to fill a DataTable using the SQL
query "SELECT TOP 0 * FROM <table>". This should return an empty table with
the appropriate DataColumns. You can also be a bit more direct and use
SqlCommand.ExecuteReader(CommandBehavior.SchemaOnly |
CommandBehavior.KeyInfo). You can then use SqlDataReader.GetSchemaTable() to
get back a table with full metadata for your original table.

Disclaimer: I tested neither of these methods.
 
How can I find out the design of a sql server 2005 table from a C# code? I'd
like to know the type and the lenght of the columns of some tables.

Thank you.

Look into the INFORMATION_SCHEMA views. In particular, in your case
the COLUMNS view.
 
Alberto said:
How can I find out the design of a sql server 2005 table from a C# code?
I'd like to know the type and the lenght of the columns of some tables.

Thank you.

You can use the same stored procedures used in SQL Server 2000....

sp_tables -- Lists tables (uses the current database)
sp_columns -- Lists columns (must specify the table name)

HTH,
Mythran
 
Back
Top