Download presentation
Presentation is loading. Please wait.
1
Microsoft SQL Server 2014 for Oracle DBAs Module 5
11: Monitoring and performance tuning Microsoft SQL Server 2014 for Oracle DBAs Module 5 Data access
2
Developing robust queries
40074A Module Overview 6: Data Access Developing robust queries
3
Lesson 1: Comparing structured query language
6: Data Access Demonstration: Transact SQL
4
Relational engine SQL OS SQL OS API In-Memory OLTP External Components
6: Data Access SQL OS SQL OS API In-Memory OLTP Deadlock Monitor Resource Monitor Lazy Writer Schedule Monitor XEvents Memory Manager Resource Governor Scheduling Synchronization I /O Hosting API External Components Protocols Query Compiler and Execution Engines Storage Engine Buffer Pool
5
Demonstration: Evaluate an execution plan
6: Data Access In this demonstration you will see how to: Provide tracing within SQL Server Review the execution plan for simple queries Compare execution plan to the trace profiler Review execution plan Demonstration Steps Click Start → All Programs → Microsoft SQL Server 2014 → Performance Tools → SQL Server Profiler. Click File → New Trace. Connect to the Training instance using Windows authentication. Trace Properties dialog box will open. Set the Trace name in Trace name textbox. Select standard (default) as Template Name. Select Event from the top tab. From among Available Event classes, click Performance → Showplan Text and add it to Selected Event classes. Click Run.Click Start → All Programs → Microsoft SQL Server 2012 → SQL Server Management Studio → New Query. Connect to the INST01 instance using Windows authentication. Select the AdventureWorks2012 database. To view the execution plan for a full table scan, type the following script in the query window: USE AdventureWorks2012 GO SELECT * FROM HumanResources.Department SELECT * FROM HumanResources.Employee Click Query → Display Estimated Execution Plan from the top navigation bar. The estimated execution plan for the full table scan will be displayed. The query is parsed and the cost of executing each component of the query is displayed by percentage. This gives a good idea as to which portion of the query is a costly operation and needs to be optimized.If your T-SQL code (More notes on the next slide)
6
Structured Query Language
6: Data Access Oracle and SQL Server are compliant with entry- level SQL-92 Both support many of the core features of SQL- 2008 Categories of SQL statements Data Definition Language (DDL) Data Manipulation Language (DML) Transaction Control Statements Session Control Statements System Control Statements
7
Data definition language
6: Data Access Define and alter database structures Using : CREATE, ALTER and DROP Access control: GRANT and REVOKE + DENY in SQL Server Identifiers limits in characters Oracle <= 30 characters SQL Server <= 128 Unicode characters Temporary tables <= 116 Unicode characters
8
Data manipulation language
6: Data Access Standard Terminology with Each Other C = INSERT R = SELECT U = UPDATE D = DELETE There are Differences Though Oracle: IN lists can have up to 1000 values SQL Server: IN lists have no limited on number of values Syntax variations – Example: Oracle: SELECT Field1 || Field2 FROM Table1 SQL Server: SELECT Field3 + Field4 FROM Table2
9
Demonstration: Transact SQL
6: Data Access In this demonstration you will see how to: Generate a query Declare and use variables and row constructors Aggregate summary data Demonstration Steps Click Start → All Programs → Microsoft SQL Server 2014 → SQL Server Management Studio → New Query. Connect to the INST01 instance using Windows authentication. Select the AdventureWorks2012 database. Execute the following query to determine the sales people with the top five quotas: SELECT TOP 5 p.FirstName, p.LastName, s.SalesQuota FROM Person.Person p INNER JOIN Sales.SalesPerson s ON p.BusinessEntityID = s.BusinessEntityID INNER JOIN Sales.SalesTerritory t ON s.TerritoryID = t.TerritoryID WHERE (t.CountryRegionCode = N'US') ORDER BY s.SalesQuota DESCTransact-SQL variables allow you to use the same values for multiple queries. Assigning values to those variables can be done via a SET statement, or in-line as is shown in this example. Execute the following queries to use the same date range for multiple queries: datetime = '10/1/2003'; datetime = '12/31/2003'; SELECT h.SalesOrderID, h.CustomerID, h.TotalDue FROM Sales.SalesOrderHeader h WHERE h.OrderDate SELECT po.PurchaseOrderID, po.OrderDate, po.TotalDue FROM Purchasing.PurchaseOrderHeader po WHERE po.OrderDate While Transact-SQL supports the older join syntax where the join conditions are specified in the WHERE clause, best practices recommend that the ANSI join syntax be used. This makes it easier to understand what the join conditions are for each join, as they’re located immediately after the table joining into the expression. SQL Server provides a way to create a column which assigns itself a unique value when a row is inserted into the table. Then, the INSERT statement doesn’t need to (More notes on the next slide)
10
Lesson 2: Control and procedural statements
6: Data Access Integrated full-text searching
11
Control Statements in Oracle and SQL Server
6: Data Access Control Statements in Oracle and SQL Server Oracle SQL Server Control Category Transaction Control COMMIT [WORK] COMMIT [WORK] TRANSACTION ROLLBACK ROLLBACK [WORK] TRANSACTION SAVEPOINT SAVE TRAN[SACTION] SET TRANSACTION SET Session Control ALTER SESSION SET ROLE sp_setapprole ALTER SYSTEM sp_configure ALTER DATABASE sp_dboption
12
Both use “BEGIN … END” and “IF” for block and conditional structuring.
SQL language support 6: Data Access Both use “BEGIN … END” and “IF” for block and conditional structuring. 1 Statement <> BEGIN … END > 1 Statement = BEGIN … END Oracle offers loop structures: LOOP … END LOOP, FOR … END LOOP, WHILE … END LOOP SQL Server offers the loop WHILE Dynamic SQL ORACLE - DBMS_SQL or EXECUTE IMMEDIATE SQL Server - sp_executesql and EXEC()
13
Declare Cursor with a SELECT
Cursors 6: Data Access Versatile navigation through data Both support Fetching and Scrolling SQL Server cursor types include: Define Variables Declare Cursor with a SELECT Open the Result Fetch the Next Row Close the Cursor FIRST NEXT PRIOR LAST ABSOLUTE RELATIVE FORWARD_ONLY INSENSITIVE SCROLL READ_ONLY STATIC DYNAMIC FAST_FORWARD LOCAL GLOBAL KEYSET-DRIVER
14
Integrated full-text searching
6: Data Access Storing large text documents is on the rise RDBMS – Not equipped on their own to handle this Oracle Text SQL Server Full-Text SELECT * FROM MYTextDocuments WHERE CONSTAINS (text, ‘Oracle’,1) > 0 SELECT * FROM MYProductCatalog WHERE CATSEARCH (title, ‘Camera’, ‘order by price desc’) > 0 SELECT * FROM MYRules WHERE MATCHES (query_strink,:doc_text) > 0 (text, ‘SQL Server’) SELECT * FROM MYTextDocuments WHERE FREETEXT SELECT * FROM MYTextDocuments FT_TBL INNER JOIN CONTAINSTABLE (MYTextDocuments, text, ‘ SQL Server’) AS K_TBL ON FT.TBL.id = K_TBL.[KEY] ORDER BY K_TBL.RANK DESC;
15
Lesson 3: Developing robust queries
40074A Lesson 3: Developing robust queries 6: Data Access Locking
16
Tools to ease development cycles
6: Data Access Tools for Creating Queries Command Line SQL *Plus for Oracle SQLCMD for SQL Server Graphical User Interfaces SQL Developer for Oracle SQL Server Management Studio NEW: SQL Server Data Tools Beyond the Integrated Tools Toad from Quest Software And others
17
Error handling Servers always raise the errors T-SQL dealings @@Error
6: Data Access Servers always raise the errors T-SQL dealings TRY..CATCH Oracle has predefined system exceptions NO_DATA_FOUND TOO_MANY_ROWS and so on SQL Server internal error messages Severity levels View with sys.messages Both DBs allow custom exceptions messages Severity Level Description 0-9 Informational message that are not severe. DB does not raise system errors. 11-16 Indicate software errors that can be corrected by the user. 17-19 Indicate software errors that cannot be corrected by the user. 20-25 Indicate fatal errors, which means executions ceases. Error messages are writing to the error log.
18
Query optimization Cost-Based Optimization Execution Plans based on:
6: Data Access Cost-Based Optimization Execution Plans based on: Access methods Statistics Hints Plans can be viewed with: Oracle Explain Plan Execution Plan
19
Transaction management
6: Data Access Oracle transactions end with COMMIT or ROLLBACK SQL Server is an implicit commit for each row. Make explicit by using: BEGIN TRAN … COMMIT TRAN or SET IMPLICIT_TRANSACTIONS ON Distributed transactions modify data in more than one database in a distributed database environment Two-phase commit provides ways to manage data consistency and data integrity in a distributed environment
20
Concurrency and consistency
6: Data Access Isolation levels and concurrency issues Concurrency and consistency are mutually opposing goals Oracle supports read-committed and serializable- isolation levels Achieves other levels through row-versioning SQL Server removes “writers blocking reader” and readers blocking writers” with snapshot-isolation SQL Server supports all four isolation levels Isolation table Dirty read Non-repeatable read Phantom read Read uncommitted Possible Read committed Not possible Repeatable read Serializable
21
SQL Server supports lock escalation
Locking 6: Data Access Locking granularity SQL Server supports lock escalation Explicit locking can be achieved by using lock hints in both DBMS Oracle locking SQL Server locking Table level Row level (default) Table Partition Page Row (default) Basic Admin next
22
© 2014 Microsoft Corporation. All rights reserved
© 2014 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.