What's the structure of a table with MS SQL Server?

This is specific to Microsoft SQL Server 2005

  • You can view the same information in a graphical format with the SQL Server Management Studio.

Summary

How to get the structure of a table with MS SQL server 2005?

Table structure

use adventureworkslt;
go
SELECT col.name AS "Column Name", col.column_id, SCHEMA_NAME(typ.schema_id) AS "Schema",
typ.name AS "Type", typ.is_user_defined, typ.is_assembly_type, col.max_length, col.precision, col.scale
FROM sys.columns AS col 
JOIN sys.types AS typ ON col.user_type_id=typ.user_type_id
WHERE col.object_id = OBJECT_ID('saleslt.address')
ORDER BY 2;
go
Column Name     column_id   Schema   Type                is_user_defined is_assembly_type max_length precision scale
--------------- ----------- -------- ------------------- --------------- ---------------- ---------- --------- -----
AddressID       1           sys      int                 0               0                4          10        0    
AddressLine1    2           sys      nvarchar            0               0                120        0         0    
AddressLine2    3           sys      nvarchar            0               0                120        0         0    
City            4           sys      nvarchar            0               0                60         0         0    
StateProvince   5           dbo      Name                1               0                100        0         0    
CountryRegion   6           dbo      Name                1               0                100        0         0    
PostalCode      7           sys      nvarchar            0               0                30         0         0    
rowguid         8           sys      uniqueidentifier    0               0                16         0         0    
ModifiedDate    9           sys      datetime            0               0                8          23        3    

(9 row(s) affected)
  • Do not forget to first select the database that you want to use.
  • This includes all the schemas.