Document

T-SQL for
Beginners
Said Salomon
Said Salomon
Unitrin Direct Insurance
[email protected]
CODE CAMP 2009.2

I have over 25 year experience IT. I have a
vast array of abilities in the field in the areas
of Network, Desktop Support, DBA, Staff
Project Management, Application Software
Development, Business Analysis and Quality
Assurance. I have Microsoft certifications as
MCTS, MCPS, and MCNPS, and multiple
certifications from the Insurance Institute of
America.

What does the T stand for?
 Transact


Structured Query Language
SQL is a database computer language
designed for managing data in database
management systems




A way to organize large amounts of data
A collation of spreadsheets
A database is a collations a Tables
A server is a collation of databases



A Table is a collations of fields (columns).
Tables have rows and each rows has columns
Tables are connected together logically with
keys and or indexes.







Basics of Microsoft SQL Management Studio
How to connect to a server
How to explore a database on the server
Basic of how to use the interface to run SQL
scripts
Create, Drop
Insert, Update
Select, Join





INNER Join – Result will contain matching records from both
tables
LEFT Join – Result will contain all records from the “left” table
even if the join-condition does not find any matching record in the
“right” table
RIGHT Join – Result will contain all records from the “right” table
even if the join-condition does not find any matching record in the
“left” table
FULL Join – Result will contain all records from both tables, and fill
in NULLs for missing matches on either side
CROSS Join – Result will contain returns the cartesian product of
the sets of records from the two joined tables (Dangerous with
large tables)
SELECT [ ALL | DISTINCT ] [ TOP ( expression ) [
PERCENT ] [ WITH TIES ] ] <select_list>
<select_list> ::= {
* | { table_name |
view_name | table_alias }.* | {
[ { table_name |
view_name | table_alias }. ]
{ column_name |
$IDENTITY | $ROWGUID }
| udt_column_name [
{ . | :: } { { property_name | field_name }
|
method_name ( argument [ ,...n] ) } ]
|
expression
[ [ AS ] column_alias ]
} |
column_alias = expression } [ ,...n ]
[ WITH <common_table_expression> [ ,...n ] ]
INSERT [ TOP ( expression ) [ PERCENT ] ] [ INTO ] { <object> |
rowset_function_limited [ WITH ( <Table_Hint_Limited> [ ...n ] ) ] }
{ [ ( column_list ) ] [ <OUTPUT Clause> ] { VALUES ( { DEFAULT |
NULL | expression } [ ,...n ] ) [ ,...n ] | derived_table | execute_statement
| <dml_table_source> | DEFAULT VALUES } } [; ] <object> ::=
{ [ server_name . database_name . schema_name . | database_name
.[ schema_name ] . | schema_name . ]
table_or_view_name }
<dml_table_source> ::= SELECT <select_list> FROM (
<dml_statement_with_output_clause> )
[AS] table_alias [ (
column_alias [ ,...n ] ) ] [ WHERE <search_condition> ] [ OPTION (
<query_hint> [ ,...n ] ) ]
[ WITH <common_table_expression> [...n] ]
UPDATE [ TOP ( expression ) [ PERCENT ] ] { <object> | rowset_function_limited [ WITH (
<Table_Hint_Limited> [ ...n ] ) ] } SET { column_name = { expression | DEFAULT | NULL } |
{ udt_column_name.{ { property_name = expression | field_name = expression } |
method_name ( argument [ ,...n ] ) } } | column_name { .WRITE ( expression , @Offset ,
@Length ) } | @variable = expression | @variable = column = expression | column_name { += |
-= | *= | /= | %= | &= | ^= | |= } expression | @variable { += | -= | *= | /= | %= | &= | ^= | |= }
expression | @variable = column { += | -= | *= | /= | %= | &= | ^= | |= } expression } [ ,...n ] [
<OUTPUT Clause> ] [ FROM{ <table_source> } [ ,...n ] ] [ WHERE {
<search_condition>
| { [ CURRENT OF
{ { [ GLOBAL ] cursor_name
}
| cursor_variable_name
}
]
}
} ] [ OPTION (
<query_hint> [ ,...n ] ) ] [ ; ] <object> ::= { [ server_name . database_name . schema_name
. | database_name .[ schema_name ] . | schema_name . ]
table_or_view_name}




Sample databases
http://msftdbprodsamples.codeplex.com/
Intro course
http://sqlcourse.com/intro.html
SQL Server 2008, Dev Edition
http://bit.ly/L2hJQ
My Twitter
SaidSalomon