Tips & Tricks SQL in the City Seattle 2014
-
Upload
ike-ellis -
Category
Technology
-
view
475 -
download
7
description
Transcript of Tips & Tricks SQL in the City Seattle 2014
![Page 1: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/1.jpg)
Tips & Tricks with SQL Server Performance Tuning, SSAS, SSRS, SSIS, and More!
By Ike Ellis, MVP@ike_ellis
www.ikeellis.comBlog.ikeellis.com
http://www.linkedin.com/in/ikeellis
![Page 2: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/2.jpg)
So you want to be great at SQL Server…SQL Server Integration ServicesSQL Server Analysis Services
TabularMultiDimensional
SQL Server Reporting ServicesExcelData Quality ServicesService BrokerPerformance Tuning
IndexingQuery PlansPlan AnalysisMemory ManagementSANsNetwork
ClusteringAvailability GroupsPowerShellMaster Data ServicesArchitectureData Mart DesignData NormalizationCDCNoSQL/BigData (At least the MS Cloud Offerings)Competitive Knowledge (Oracle, Tablaeu, QlickView, Postgres)ORMs(Entity Framework, Nhibernate, Micros)Installation/Configuration/Upgrading/Service Packing
Power BIPowerMapPowerQueryPowerView
PowerPivotT-SQL
QueryingStored ProceduresFunctionsWindowing FunctionsAggregates
CLRMDXDAXXMLABCPSQL AzureTooling
RedgateSSMSSSDT
Past VersionsCentral ManagementDacPacs/BacPacsProfiler/Extended EventsAuditingSecurity/EncryptionReplicationSQLCMD
![Page 3: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/3.jpg)
Tips From the SQL Consultant• For the
YouTube/Reddit/Chive/Cracked/Meme generation
• Lots of disjointed tips• Popular mistakes I see or easy things I
think you can take advantage of• Between 3 – 5 minutes each• Let’s see if we can get through all 20
![Page 4: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/4.jpg)
TIP #1: Query Shortcuts
• SELECT COUNT(*) FROM • SELECT TOP 100 * FROM
![Page 5: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/5.jpg)
TIP #2: Don’t forget the splitter bar
![Page 6: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/6.jpg)
TIP #3: Low hanging fruit
• CRTL-R– F6 switches between result tabs
• Copy, Paste a line without selecting• COMMENTS CTRL-K, C, CTRL-K U• BOOKMARKS CTRL-K, K, CTRL-K N• Refresh cache – CTRL-SHIFT R– Unless RedGate then CTRL-SHIFT D
![Page 7: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/7.jpg)
TIP #4: Block Commenting
• Easy column selection – bring up the query window– CTRL-SHIFT Q
• Format the columns comma first, like you’re supposed to– SQL PROMPT – CTRL-K, CTRL-Y
• Alias a table• CTRL-ALT arrow• Add alias
![Page 8: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/8.jpg)
TIP #5: Code Snippets
• CTRL-K, CTRL-B – Bring up Code Snippet Manager
• Copy an existing one from a path and put it in the My Snippets Path
• Edit the XML• CTRL-K, CTRL-X to place the snippet• Great for common queries– WhoIsActive – sp_Blitz– DBCC OPENTRAN
![Page 9: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/9.jpg)
Tip #6: SSIS for the Color Blind
![Page 10: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/10.jpg)
Tip #7: Five minutes on report formatting = 10x more impressive
• Spend 10 minutes on design (as opposed to the zero we typically spend)
• Choose colors wisely – 99/100 - developers use the default
color palette • HTML color picker websites – http://www.lavishbootstrap.com
• MorgueFile– http://www.morguefile.com/
![Page 11: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/11.jpg)
11
Tip #8: The right way to find hardware problems
• Merging PerfMon and Tracing• Get the Batch and Completed Events Only• Never trace from the computer you are
monitoring• Always trace to a file and then load in a
table after.
*Thanks, Grant!
![Page 12: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/12.jpg)
Tip #9: Lifehack: Readable Presentations
• Take the average age of the people in your audience and divide by 2: That’s your font size
•USE THIS SIZE IF YOUR AUDIENCE IS 110
![Page 13: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/13.jpg)
Tip #10: Check for heaps/clustered indexes
SELECT t.[Name] FROM sys.Indexes i JOIN sys.Tables t ON t.Object_ID = i.Object_idWHERE i.type_desc = 'HEAP'ORDER BY t.[Name]
![Page 14: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/14.jpg)
Tip #11: The proper way to run an SSIS package
![Page 15: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/15.jpg)
Tip #12: No reason to use ISNULL CONCAT!
• Messy vs clean code• No + symbol needed• No ISNULL needed
![Page 16: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/16.jpg)
Tip #13: How to search schema
• F7• SQLSearch
– Free– Download it!– http://www.red-gate.com/products/sql-development/sql-
search/
– Did I mention it’s free?• Dependency Tracker
– Not Free, but still cool
select object_name(object_id), definition as namefrom sys.all_sql_moduleswhere definition like '%cust%'
![Page 17: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/17.jpg)
Tip #14: Windowing Functions are pretty cool
• They are worth learning, and have a neat evolution
![Page 18: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/18.jpg)
Tip #15: SSDT Search for options
• No more digging around in options• Just search for everything
![Page 19: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/19.jpg)
Tip #16: Scripting: You have two choices
• Two Choices– Get good at boring repetitive tasks– Get good at PowerShell & Scripting
• Who adds more value to their company or their customers?
• Who gets paid more?
![Page 20: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/20.jpg)
Tip #17: TempDB Configuration
• Current thought is 4 logical processors to 1 file
• Just a good beginning, your mileage may very
• Start there, then go to 2:1 or 1:1 if necessary
• Trace Flag 1117 or autogrow off
![Page 21: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/21.jpg)
21
Tip #18: Prettify!
http://extras.sqlservercentral.com/prettifier/prettifier.aspx
RedGate PlugIn for SQL Server Management Studio
![Page 22: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/22.jpg)
Tip #19: Execute scripts over multiple servers?
• Super easy!
![Page 23: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/23.jpg)
Tip #20: Life is so easy with a dates table
• Find the sales numbers for the first Monday of every month of the year
• T-SQL with no dates table• T-SQL with dates table
![Page 24: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/24.jpg)
Tip #21: Try_Cast
• Avoiding terrible casting errors
![Page 25: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/25.jpg)
Tip #22: Never reinvent the wheel
• Take SQL# for example• Good Documentation• Easy Syntax• Cheap (and much of it is free)
![Page 26: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/26.jpg)
Tip #23: Save scripts for easy access
• Lots of repetitive scripts with business logic
• No reason to write the same queries for the same tables day after day
![Page 27: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/27.jpg)
27
Tip #24: Enforce Business Rules in the DB
• Foreign Keys• Unique Constraints• Check Constraints
![Page 28: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/28.jpg)
Tip #25: Log, Log, Log (and beware of subscriptions)
select c.Name, e.InstanceName, e.UserName, e.Parameters, e.TimeStart, e.TimeEnd, e.TimeDataRetrieval, e.TimeProcessing, e.TimeRenderingfrom executionlog e join catalog c on e.reportid = c.ItemID
Send a Link, or a file on a shared folder that you can audit. Find someway to audit who opened the link or the file in the folder. Try to avoid sending the PDF without a way to audit it.
![Page 29: Tips & Tricks SQL in the City Seattle 2014](https://reader035.fdocuments.net/reader035/viewer/2022070321/558a1820d8b42af6378b45ce/html5/thumbnails/29.jpg)
Ike Ellis
• http://blog.ikeellis.com• http://www.ikeellis.com• YouTube – http://www.youtube.com/user/IkeEllisData
• SQL Pass Book Readers – http://bookreaders.sqlpass.org/
• San Diego Tech Immersion Group• Twitter: @ike_ellis• 619.922.9801• Email address is just my first name
@ikeellis.com