Few ways to get table columns in SQL Server:

Using sp_help

   1: EXEC sp_help 'SalesLT.Customer'

Using INFORMATION_SCHEMA

   1: SELECT 
   2:     * 
   3: FROM 
   4:     INFORMATION_SCHEMA.COLUMNS
   5: WHERE 
   6:     TABLE_CATALOG = 'SalesLT' 
   7:     AND TABLE_SCHEMA = 'SalesLT'
   8:     AND TABLE_NAME = 'Customer'

Using sys.columns DMV

   1: SELECT [name]
   2: FROM sys.columns
   3: WHERE OBJECT_NAME(object_id) = 'Customer'

 

Another userful tip:

Sometimes we need to specify column names in our T-SQL statements (INSERT/UPDATE/DELETE). It is very tedious to try and write them ourselves. Good thing in SSMS, you can drag the columns folder onto the code editor and this will list out all the columns in the table.

SQL Server Tip On Getting Table Columns

VN:F [1.4.0_681]
Rating: 10.0/10 (3 votes cast)
Share :
  • Digg
  • del.icio.us
  • Google
  • description
  • StumbleUpon
  • Technorati
  • TwitThis

Related posts:

  1. How to Search for Columns in SQL Server ...
  2. SQLXML : How to List Columns That Have the XML Data Type ...
  3. Order of Attribute-Centric Columns in FOR XML PATH matters ...
  4. SQL Server PowerShell : Search for SQL Server Objects Using PowerShell ...
  5. SQL Server PowerShell : Basics – Connecting to SQL Server ...
  6. Selecting and Executing Commented T-SQL Code ...