Skip to content

Instantly share code, notes, and snippets.

@Chetan496
Last active December 23, 2016 11:05
Show Gist options
  • Save Chetan496/0bf94767af55bcc7e07c6725307ce9c9 to your computer and use it in GitHub Desktop.
Save Chetan496/0bf94767af55bcc7e07c6725307ce9c9 to your computer and use it in GitHub Desktop.
Small snippets which explain Transact SQL (the SQL flavor used by MS-SQL)

SQL syntax in MS-SQL

Note: {} denotes placeholder. You can replace it with a real object/entity name in DB

Switching to a Database schema in MS-SQL:

USE {databasename}; GO

Show all tables in the Selected Database schema

SELECT * FROM information_schema.tables;

find all the tables in the DB along with their Database schema names:

SELECT '['+SCHEMA_NAME(schema_id)+'].['+name+']' AS SchemaTable FROM sys.tables

Select all employees from the Employee table:

SELECT * FROM dbo.EMPLOYEE;

Equivalent of DESC in Sql server - usage of EXEC

You can view the information of the columns of a table using the below syntax: EXEC sp_columns dbo.EMPLOYEE;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment