Download presentation
Presentation is loading. Please wait.
Published byMagnus Warren Modified over 8 years ago
1
Jeremy Kingry, eBECS | jkingry@ebecs.com ADVANCED SQL SERVER FOR ADMINS AND ANALYSTS
3
Course Overview SQL Server Management Studio (SSMS) Joins, INNER, OUTER, FULL Aggregates and Grouping Temp Tables
4
Course Overview Advanced SQL Functions SQL Create User SQL BACKUP, RESTORE SQL Jobs and Maintenance Plans
5
SQL JOINS - INNER JOIN Returns rows when there is a match between BOTH tables SELECT table1.column, table2.column FROM table1 INNER JOIN table 2 ON table1.key = table2.key
6
SQL Joins - INNER JOIN
7
SQL JOINS – LEFT OUTER JOIN Complete set of records from Table1, with the matching records (where available) in Table2 SELECT table1.column, table2.column FROM table1 LEFT JOIN table 2 ON table1.key = table2.key
8
SQL JOINS – LEFT OUTER JOIN
9
SQL JOINS – RIGHT OUTER JOIN Complete set of records from Table2, with the matching records (where available) in Table1 SELECT table1.column, table2.column FROM table1 RIGHT JOIN table 2 ON table1.key = table2.key
10
SQL JOINS – RIGHT OUTER JOIN
11
SQL JOINS – FULL OUTER JOIN Produces the set of all records in Table1 and Table2, with matching records from both sides where available SELECT table1.column, table2.column FROM table1 FULL JOIN table 2 ON table1.key = table2.key
12
SQL JOINS – FULL OUTER JOIN
13
SQL JOINS DEMO
14
AGGREGATE FUNCTIONS Aggregate functions perform a calculation on a set of values and return a single value. SELECT aggregate(column1) FROM table1
15
AGGREGATE FUNCTIONS AVG() - Returns the Average Value COUNT() - Returns the Number of Rows MAX() - Returns the Largest Value MIN() - Returns the Smallest Value SUM() - Returns the Sum STDEV() – Returns the Standard Deviation
16
AGGREGATE FUNCTIONS SELECT dg.StateProvinceName, SUM(sls.SalesAmount) FROM dbo.FactInternetSales AS sls INNER JOIN dbo.DimCustomer AS dc ON sls.CustomerKey = dc.CustomerKey INNER JOIN dbo.DimGeography AS dg ON dc.GeographyKey = dg.GeographyKey Column 'dbo.DimGeography.StateProvinceName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
17
GROUP BY The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns. SELECT dg.StateProvinceName, SUM(sls.SalesAmount) FROM dbo.FactInternetSales AS sls INNER JOIN dbo.DimCustomer AS dc ON sls.CustomerKey = dc.CustomerKey INNER JOIN dbo.DimGeography AS dg ON dc.GeographyKey = dg.GeographyKey GROUP BY dg.StateProvinceName
18
GROUP BY StateProvinceNameSalesAmount Alabama37.29 Alberta22467.8025 Arizona2104.0196 Bayern399966.7822
19
HAVING and ORDER BY HAVING allows a “WHERE” type criteria for aggregate functions ORDER BY allows sorting query results
20
HAVING and ORDER BY SELECT dg.StateProvinceName, dg.EnglishCountryRegionName, SUM(sls.SalesAmount) AS SalesAmount FROM dbo.FactInternetSales AS sls INNER JOIN dbo.DimCustomer AS dc ON sls.CustomerKey = dc.CustomerKey INNER JOIN dbo.DimGeography AS dg ON dc.GeographyKey = dg.GeographyKey GROUP BY dg.StateProvinceName, dg.EnglishCountryRegionName HAVING SUM(sls.SalesAmount) > 30000 ORDER BY dg.EnglishCountryRegionName
21
AGGREGATE FUNCTIONS DEMO
22
TEMP TABLES Can Improve Performance Allows for Temporary Data Manipulation Reduces Table Locking Can be Indexed Can be Reference by More than one Query Identified with #
23
TEMP TABLES CREATE TABLE #tempCust ( CustomerKey INT, CustomerName VARCHAR(150) )
24
TEMP TABLES DEMO
25
ADVANCED SQL FUNCTIONS ROW_NUMBER – Returns sequential row numbers within a partition of a result set RANK – Rank for each row of a partition within a set NTILE – Splits the set into n tiles (quartile etc)
26
ADVANCED SQL FUNCTIONS DEMO
27
Users and Logins Creating a Login and User are one of the first primary functions of a dba. This procedure allows granting and revoking access to database objects to ensure a user can not only get to the data they need but they are also prevented from performing actions they should not be allowed to do.
28
Users and Logins 1.Login - grants or revokes server access 2.User - grants or revokes database access 3.Login can be SQL or Windows domain account 4.User must have a login 5.Login has one user per database
29
CREATE LOGIN AND USER DEMO
30
BACKUP Having a proper backup strategy is essential to ensuring uptime and safety of the data stored in MS SQL Server. Designing a proper strategy including backup types, timings, and storage options is essential for todays modern systems where downtime and lost data can cost millions.
31
BACKUP 1.How many hours a day do applications have to access the database? 2.How frequently are changes and updates likely to occur? 3.Are changes likely to occur in only a small part of the database or in a large part of the database? 4.How much disk space will a full database backup require?
32
Backup – Full Backup Backs up entire database Most reliable method but takes a long time Consumes a lot of space even compressed Simplest to restore (one step)
33
Backup – Differential Backup Backs up all changes since last full backup Must have at least one full backup before starting differential backups Are cumulative in nature so only have to restore latest full and latest diff backup Conserves space and time backing up
34
Backup – Transaction Log Backup Captures all changes written to the transaction log since last full or log backup Must have at least one full backup before starting log backups Allows backing up frequently enough to prevent large data losses Conserves space and time backing up
35
Backup – Tail Log Backup Works in event of corrupt database but the transaction log is still available Backs up the tail of the log from the last backup to the time of the error occurring Use only when a problem has occurred to minimize data loss
36
Backup – Backup Strategy Weekly full backup Nightly differential backups Transaction log backups every four hours Adjust for needs and volume
37
BACKUP BACKUP DATABASE { database_name } TO [ WITH { DIFFERENTIAL | [,...n ] } ]
38
RESTORE Once a database has been backed up you hope to never have to use it but if you do RESTORE is the way to recover the backup copy. Restore can be performed from the user interface or through the SQL Command RESTORE.
39
RESTORE RESTORE DATABASE { database_name } [ FROM [,...n ] ] [ WITH { [ RECOVERY | NORECOVERY | STANDBY = {standby_file_name | @standby_file_name_var } ] |, [,...n ] |, } [,...n ] ]
40
BACKUP AND RESTORE DEMO
41
SQL Jobs and Notifications 1.Ability to schedule tasks 2.Notify people on job status: a.Job Completes b.Job Fails c.Job Succeeds 3.Automate manual processes
42
Database Maintenance Plan 1.Workflow creation of maintenance tasks 2.Easy wizard driven creation 3.Performance tuning multiple databases 4.Manage backup tasks 5.Can clean up after itself
43
Additional Topics 1.SQL Logs (Management -> SQL Server Logs) 2.Standard Reports (Right Click DB and Choose Reports)
44
SQL JOB AND MAINTENANCE DEMO
45
QUESTIONS
46
46 #AXUGFocus CPE Credit Code: 53C2 Complete Surveys FINAL REMINDERS
47
47 #AXUGFocus Jeremy Kingry eBECS ltd jkingry@ebecs.com @Jeremy_Kingry https://www.linkedin.com/in/jskingry SPEAKER CONTACT INFO
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.