MSSQL

From WhyAskWhy.org Wiki
Revision as of 16:27, 10 December 2014 by Deoren (talk | contribs) (Added an example of using stored procedure)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search


Microsoft SQL Server 2008 Tips/Tricks

For all examples shown here, the database if not explicitly shown is named Services. Snippets were tested on Microsoft SQL Server 2008.


Show all columns of a database table

[1] [2]

Examples (mostly 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'
    
  • exec sp_help '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