said salomon unitrin direct insurance timelord@timelordshangout.com t-sql for beginners said salomon...

Post on 13-Jan-2016

212 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Said SalomonUnitrin Direct Insurance

timelord@timelordshangout.com

T-SQL for BeginnersSaid Salomon

CODE CAMP 2009.2

Who am I?

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.

SQL Server

What is T-SQL?

What does the T stand for? Transact

Structured Query LanguageSQL is a database computer

language designed for managing data in database management systems

What is a database?

A way to organize large amounts of data

A collation of spreadsheetsA database is a collations a TablesA server is a collation of databases

What is a table?

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.

Demo

Basics of Microsoft SQL Management Studio

How to connect to a serverHow to explore a database on the

serverBasic of how to use the interface to

run SQL scriptsCreate, Drop Insert, UpdateSelect, Join

Type of Joins

Type of Joins

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

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 ]

Insert

[ 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 ] ) ]

Update

[ 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}

Resources

Sample databases http://msftdbprodsamples.codeplex.com/

Intro coursehttp://sqlcourse.com/intro.html

SQL Server 2008, Dev Edition http://bit.ly/L2hJQ

My TwitterSaidSalomon

top related