MSSQL

From WhyAskWhy.org Wiki
Revision as of 16:21, 10 December 2014 by Deoren (talk | contribs) (Stub page.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Note: Examples shown here were tested on Microsoft SQL Server 2008.

Microsoft SQL Server 2008 Tips/Tricks

Overview

For all examples shown here, the database if not explicitly shown is named Services.

Show all columns of a database table

[1]

Examples (equivalent results):

  • SELECT name FROM sys.columns WHERE object_id = OBJECT_ID('dbo.Users')
    
  • SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='Services.dbo.Users'
    

In my case I had drilled down using the Microsoft SQL Server Management Studio prior to running the queries, so the tables could have simply been specified as Users with the same result.

References