said salomon unitrin direct insurance [email protected] t-sql for beginners said salomon...

13
Said Salomon Unitrin Direct Insurance timelord@timelordshangout. com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

Upload: angel-charles

Post on 13-Jan-2016

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

Said SalomonUnitrin Direct Insurance

[email protected]

T-SQL for BeginnersSaid Salomon

CODE CAMP 2009.2

Page 2: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said 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.

Page 3: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

SQL Server

Page 4: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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

Page 5: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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

Page 6: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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.

Page 7: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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

Page 8: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

Type of Joins

Page 9: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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)

Page 10: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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 ]

Page 11: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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

Page 12: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

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}

Page 13: Said Salomon Unitrin Direct Insurance timelord@timelordshangout.com T-SQL for Beginners Said Salomon CODE CAMP 2009.2

Resources

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

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

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

My TwitterSaidSalomon