Jeremy Kingry, eBECS | ADVANCED SQL SERVER FOR ADMINS AND ANALYSTS.

Slides:



Advertisements
Similar presentations
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 5 More SQL: Complex Queries, Triggers, Views, and Schema Modification.
Advertisements

Concepts of Database Management Sixth Edition
Concepts of Database Management Seventh Edition
FlareCo Ltd ALTER DATABASE AdventureWorks SET PARTNER FORCE_SERVICE_ALLOW_DATA_LOSS Slide 1.
DataBase Administration Scheduling jobs Backing up and restoring Performing basic defragmentation and index rebuilding Using alerts Archiving.
SQL Server Best Practices Keep Your Database In Top Performance Shape and Maintain Effective Backups September, 2007 Richard Kokoski.
Fundamentals, Design, and Implementation, 9/e Chapter 11 Managing Databases with SQL Server 2000.
1 Introduction to Web Application Introduction to Data Base.
Database Systems More SQL Database Design -- More SQL1.
Week 9 – Chapter 8 SQL 710 Methods to Backup Databases
Module 7: Restoring Databases. Overview SQL Server Recovery Process Preparing to Restore a Database Restoring Backups Restoring Databases from Different.
National Manager Database Services
70-290: MCSE Guide to Managing a Microsoft Windows Server 2003 Environment, Enhanced Chapter 12: Managing and Implementing Backups and Disaster Recovery.
Today’s Agenda Chapter 12 Admin Tasks Chapter 13 Automating Admin Tasks.
SQL Server 2008 Implementation and Maintenance Chapter 7: Performing Backups and Restores.
SQL and Support Debugging Tool Paul Johnson and Graham O’Bray.
© Paradigm Publishing Inc. 9-1 Chapter 9 Database and Information Management.
CSE314 Database Systems More SQL: Complex Queries, Triggers, Views, and Schema Modification Doç. Dr. Mehmet Göktürk src: Elmasri & Navanthe 6E Pearson.
15 Copyright © 2005, Oracle. All rights reserved. Performing Database Backups.
Sofia, Bulgaria | 9-10 October SQL Server 2005 High Availability for developers Vladimir Tchalkov Crossroad Ltd. Vladimir Tchalkov Crossroad Ltd.
16 Copyright © 2007, Oracle. All rights reserved. Performing Database Recovery.
Physical Database Design & Performance. Optimizing for Query Performance For DBs with high retrieval traffic as compared to maintenance traffic, optimizing.
HAP 709 – Healthcare Databases SQL Data Manipulation Language (DML) Updated Fall, 2009.
© Paradigm Publishing Inc. 9-1 Chapter 9 Database and Information Management.
Architecture Rajesh. Components of Database Engine.
Module 6 Backup of SQL Server 2008 R2 Databases. Module Overview Backing up Databases and Transaction Logs Managing Database Backups Working with Backup.
Learningcomputer.com SQL Server 2008 – Administration, Maintenance and Job Automation.
IT 456 Seminar 5 Dr Jeffrey A Robinson. Overview of Course Week 1 – Introduction Week 2 – Installation of SQL and management Tools Week 3 - Creating and.
Using Special Operators (LIKE and IN)
11 DISASTER RECOVERY Chapter 13. Chapter 13: DISASTER RECOVERY2 OVERVIEW  Back up server data using the Backup utility and the Ntbackup command  Restore.
6 1 Lecture 8: Introduction to Structured Query Language (SQL) J. S. Chou, P.E., Ph.D.
Intro to SQL Management Studio. Please Be Sure!! Make sure that your access is read only. If it isn’t, you have the potential to change data within your.
SQL 101 – Class 1 Lee Turner. Agenda 1. This is your life – SQL A brief history of SQL What SQL is and what it is not Normalization 2. Some Super Simple.
Database structure and space Management. Database Structure An ORACLE database has both a physical and logical structure. By separating physical and logical.
IS 230Lecture 6Slide 1 Lecture 7 Advanced SQL Introduction to Database Systems IS 230 This is the instructor’s notes and student has to read the textbook.
1 Principles of Database Systems With Internet and Java Applications Today’s Topic Chapter 15: Reliability and Security in Database Servers Instructor’s.
Database Fundamental & Design by A.Surasit Samaisut Copyrights : All Rights Reserved.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 (Part II) INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor.
Concepts of Database Management Seventh Edition Chapter 3 The Relational Model 2: SQL.
Learningcomputer.com SQL Server 2008 – Backup and Restore Database.
SQL LANGUAGE TUTORIAL Prof: Dr. Shu-Ching Chen TA: Hsin-Yu Ha.
Database Systems, 8 th Edition SQL Performance Tuning Evaluated from client perspective –Most current relational DBMSs perform automatic query optimization.
Introduction to Core Database Concepts Getting started with Databases and Structure Query Language (SQL)
Log Shipping, Mirroring, Replication and Clustering Which should I use? That depends on a few questions we must ask the user. We will go over these questions.
Digging Out From Corruption Eddie Wuerch, MCM - Principal, Database Performance - Salesforce Marketing Cloud Data protection and loss recovery with SQL.
Backing Up and Restoring Databases Advanced Database Dr. AlaaEddin Almabhouh.
Concepts of Database Management, Fifth Edition Chapter 3: The Relational Model 2: SQL.
Agenda for Today  DATABASE Definition What is DBMS? Types Of Database Most Popular Primary Database  SQL Definition What is SQL Server? Versions Of SQL.
ProgressBook Suite Maintenance
More SQL: Complex Queries, Triggers, Views, and Schema Modification
SQL Query Getting to the data ……..
Database Administration
More SQL: Complex Queries,
Curacao SQL Saturday June 11, 2016
An Refresher and How-To Profile Data using SQL
Maximum Availability Architecture Enterprise Technology Centre.
Building Effective Backups
SQL: Advanced Options, Updates and Views Lecturer: Dr Pavle Mogin
Chapter 9 Database and Information Management.
Backup and Restore your SQL Server Database
More SQL: Complex Queries, Triggers, Views, and Schema Modification
Database systems Lecture 3 – SQL + CRUD
SQL Fundamentals in Three Hours
Chapter 11 Managing Databases with SQL Server 2000
Sql Saturday Philadelphia
Ch 10. Maintaining and Automating SQL Server
New Perspectives on Microsoft
Intermediate Query Structure and Development
Presentation transcript:

Jeremy Kingry, eBECS | ADVANCED SQL SERVER FOR ADMINS AND ANALYSTS

Course Overview SQL Server Management Studio (SSMS) Joins, INNER, OUTER, FULL Aggregates and Grouping Temp Tables

Course Overview Advanced SQL Functions SQL Create User SQL BACKUP, RESTORE SQL Jobs and Maintenance Plans

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

SQL Joins - INNER JOIN

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

SQL JOINS – LEFT OUTER JOIN

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

SQL JOINS – RIGHT OUTER JOIN

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

SQL JOINS – FULL OUTER JOIN

SQL JOINS DEMO

AGGREGATE FUNCTIONS Aggregate functions perform a calculation on a set of values and return a single value. SELECT aggregate(column1) FROM table1

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

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.

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

GROUP BY StateProvinceNameSalesAmount Alabama37.29 Alberta Arizona Bayern

HAVING and ORDER BY HAVING allows a “WHERE” type criteria for aggregate functions ORDER BY allows sorting query results

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) > ORDER BY dg.EnglishCountryRegionName

AGGREGATE FUNCTIONS DEMO

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 #

TEMP TABLES CREATE TABLE #tempCust ( CustomerKey INT, CustomerName VARCHAR(150) )

TEMP TABLES DEMO

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)

ADVANCED SQL FUNCTIONS DEMO

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.

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

CREATE LOGIN AND USER DEMO

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.

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?

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)

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

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

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

Backup – Backup Strategy Weekly full backup Nightly differential backups Transaction log backups every four hours Adjust for needs and volume

BACKUP BACKUP DATABASE { database_name } TO [ WITH { DIFFERENTIAL | [,...n ] } ]

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.

RESTORE RESTORE DATABASE { database_name } [ FROM [,...n ] ] [ WITH { [ RECOVERY | NORECOVERY | STANDBY = {standby_file_name } ] |, [,...n ] |, } [,...n ] ]

BACKUP AND RESTORE DEMO

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

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

Additional Topics 1.SQL Logs (Management -> SQL Server Logs) 2.Standard Reports (Right Click DB and Choose Reports)

SQL JOB AND MAINTENANCE DEMO

QUESTIONS

46 #AXUGFocus CPE Credit Code: 53C2 Complete Surveys FINAL REMINDERS

47 #AXUGFocus Jeremy Kingry eBECS SPEAKER CONTACT INFO