Presentation is loading. Please wait.

Presentation is loading. Please wait.

6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration.

Similar presentations


Presentation on theme: "6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration."— Presentation transcript:

1 6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration area to be entered in additional drawings. Want more free training? Check out the Houston Area SQL Server User Group which meets on the 2 nd Tuesday of each month. Details at http://houston.sqlpass.org http://houston.sqlpass.org Thank You Sponsors!

2 SQL & Microsoft SQL Server for Builders of Software ( SQL Server - Tips, Tricks, and Other Good Stuff ) Dane Schilling Year Old Headspringer Sprung: 4/1/2014

3 You’re in good hands... ●6 years of report writing o Cognos, Crystal, and SSRS ●3 years of MS SQL Server Administration ●3 years of.NET Development ●Passionate about SQL ●Learning from new mistakes everyday

4 Agenda ●Things to check ●DR/HA ●T-SQL ●Goodies

5 ●Google with keyword tsql ●Who to trust: Paul Randal, Kimberly Tripp, Brent Ozar..and others ●Great resource: www.sqlservercentral.comwww.sqlservercentral.com ●It depends Oddities...

6 Things to check Really...please check these things

7 ●Development and test databases should be in simple mode ●Databases should not be left in bulk-logged ●Don’t arbitrarily change recovery models o This will affect backups and behavior ●If not in simple mode you MUST take log backups Recovery Model

8 Two Gotchas... ●SQL Server 2012 bug (fixed in CU7) with model database ●RoundHouse bug (fixed in version 0.8.6) default to full mode

9 Database Maintenance Check that the following are occurring on some schedule (on all environments): ●Backups ●CHECKDB* ●Statistics Updates ●Index Maintenance ●History Cleanup

10 Security ●sa account should be disabled ●Best to use Windows authentication only ●Grant minimal rights* *Hard to do

11 Files At a minimum add at least one file; this at least separates the system data from your data. The more separation you have the more restoration options you have - it isn’t magic though.

12 Indexes ●Clustered = physical sort (only one allowed, avoid heaps) ●Others are non-clustered ●Double edged sword ●Foreign keys are not automatically indexed

13 Questions?

14 Disaster Recovery & High Availability These things are important to our stakeholders.

15 Disaster Recovery ●Backups are worthless if they can’t be restored...ask someone to restore one occasionally ●You cannot restore to a point in time in simple mode and sometimes not in bulk- logged

16 High Availability ●Ask stakeholders if they have any replicated DBs, mirrors or AlwaysOn systems in place...bad things can happen if you ignore their existence o High latency o Delayed log truncation (file growth) o Replication hell

17 AlwaysOn ●2012+ high availability option ●Super awesome o Multiple read replicas o Connection strings can be set to take advantage of read only replicas if available (ApplicationIntent) o Great for reporting

18 Questions?

19 T-SQL Microsoft’s blend of SQL

20 RBAR - Row By Agonizing Row When working with a database always leverage its ability to work with sets. If you find yourself trying to loop through rows then you are going about it the wrong way.

21 Joins ●List Tables Together o Join tables together in WHERE clause ●JOIN o Only returns matches ●INNER JOIN o Same as just JOIN ●FULL (FULL OUTER) JOIN o Returns all matches and all remaining non-matched rows ●LEFT (LEFT OUTER) JOIN o Returns all matches and all remaining rows from left source ●RIGHT (RIGHT OUTER) JOIN o Returns all matches and all remaining rows from right source ●CROSS JOIN o Returns all combinations (no on clause)

22

23

24

25

26

27

28 Gotcha

29 Temp tables, table variables and CTEs #Temp ●tempdb ●indexes ●connection scope @Variable ●memory ●primary key ●batch scope ; CTE ●different ●request

30 Working with Sets ●UNION ( ALL ) ●INTERSECT ●EXCEPT ●MERGE

31 Aggregates and Window Functions ●Aggregates o ROW_NUMBER() o RANK() o NTILE() o DENSE_RANK() o COUNT() o AVG() o etc…. ●Window Functions o OVER o PARTITION BY o ORDER BY o Can’t do COUNT(DISTINCT) o Don’t require GROUP BY (duplicates)

32 Subqueries ●Can be used in o SELECT o CASE o WINDOW FUNCTION o FROM o JOIN o WHERE o ORDER BY ●Can’t be used in o Aggregates o GROUP BY

33 Stored Procedures and Views ●Stored Procedures o Offer performance improvements o Accept parameters o Can’t be included with other queries o Code consistency and reusability ●Views o Don’t offer performance improvements (unless indexed) o Can be included in other queries o Code consistency and reusability

34 Functions ●Table and Scalar o Use with caution o Must be performant o Number of calls can be dramatic ●Table - Multi vs Single (Inline) ○Can be used with APPLY ■CROSS ■OUTER ●Scalar ○SELECT ○Clauses (ON and WHERE) ○ORDER BY ○GROUP BY

35 Questions?

36 Goodies!!! Now for some cool stuff???

37 CTE Trick Power of simple math!!! http://www.sqlservercentral.com/articles/T-SQL/67899/

38

39

40

41

42

43 4K Splitter...also from sqlservercentral.com http://www.sqlservercentral.com/articles/Tally+Table/72993/

44

45 FOR XML PATH...I don’t remember where I saw this for the first time. I just know I love to abuse it.

46

47

48

49

50

51

52 Going a little crazy... You can use the XML CLR to build HTML!!!!!!!!!

53 Questions?


Download ppt "6/13/2015 Visit the Sponsor tables to enter their end of day raffles. Turn in your completed Event Evaluation form at the end of the day in the Registration."

Similar presentations


Ads by Google