Monday, March 30, 2009

SQL: List of common commands

Here is a list of basic T-SQL commands that you should know in order to work with the queries in Management Studio. You can find them in the web very quickly using a search engine, but I chose to list some here just in case and for my personal reference:

use "database_name"

execute the query on a database

Simple query example structure for basic operations:

select "values" from "table"

select row results from a table, make a query
use * to get all values

order by
order results, by default the order is of finding.
you can force desc - descending
asc - ascending

select ExtracData from stg.ExtractLog where DataSource = 'HRData'
order by 'Size'

backup database "DataBaseName"
to disk = '"path"'

generates a backup off a specific database to disk location
commonly used with “SQL Server Agent” activated

dbcc showcontig ('"TableName"')

shows information about paging tables, number off reads, accesses, etc
good for optimization analisys

with tableresults
extra paramater (optional) that shows result as a table

No comments: