+ All Categories
Home > Documents > Module 5: Data Access. Overview Introduce database components involved in data access Introduce...

Module 5: Data Access. Overview Introduce database components involved in data access Introduce...

Date post: 23-Dec-2015
Category:
Upload: laura-mcdonald
View: 219 times
Download: 1 times
Share this document with a friend
17
Module 5: Data Access
Transcript
Page 1: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Module 5:Data Access

Page 2: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Overview

Introduce database components involved in data access

Introduce concepts of Transact -SQL and Procedural SQL as tools to access and manipulate data

Discuss transactional management concepts

Page 3: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Relational Engine

SQL CLR Hosting Layer

Synchronization Svcs

Scheduler

Lock Manager

Deadlock Monitor

Buffer Pool

Memory Manager

SQLOS

SQLManager

T-SQLExecution

CLR

QueryExecution

T-SQL Compiler

Algebraizer

QueryOptimizer

Parser

Expression S

vcsExecution EnvironmentMETADATA Interface

Storage Engine

SQL Messages

HTTP Messages

RPCMessages

Results

Page 4: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Demonstration 1: Evaluate an Execution Plan

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

Page 5: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Structured Query Language

Oracle and SQL Server are compliant with entry-level SQL-92

Both support many of the core features of SQL-99 and SQL-2003

Categories of SQL statements

• Data Definition Language (DDL)

• Data Manipulation Language (DML)

• Transaction Control Statements

• Session Control Statements

• System Control Statements

Page 6: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Data Definition Language (DDL)

Define and alter database structures

Using :

CREATE, ALTER and DROPAccess 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

Page 7: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Data Manipulation Language (DML)

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

Page 8: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Demonstration 2: Transact–SQL

In this demonstration you will see how to:

Generate a query

Declare and use variables and row constructors

Aggregate summary data

Page 9: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Control Statements

Control Statements in Oracle and SQL Server

Control Category

Oracle SQL Server

Transaction Control COMMIT [ WORK ] COMMIT [ WORK | TRANSACTION ]

Transaction Control ROLLBACK ROLLBACK [ WORK | TRANSACTION ]

Transaction Control SAVEPOINT SAVE TRAN[SACTION]

Transaction Control SET TRANSACTION SET

Session Control ALTER SESSION SET

Session Control SET ROLE sp_setapprole

System Control ALTER SYSTEM sp_configure

System Control ALTER DATABASE sp_dboption

Page 10: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Procedural and Transaction - SQL

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 WHILEDynamic SQL

ORACLE - DBMS_SQL or EXECUTE IMMEDIATE SQL Server - sp_executesql and EXEC()

Page 11: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Cursors

Versatile navigation through data

Both support Fetching and Scrolling

SQL Server cursor types include:

FIRSTNEXTPRIORLAST

ABSOLUTERELATIVE

FORWARD_ONLYINSENSITIVESCROLL READ_ONLYSTATIC

DYNAMICFAST_FORWARDLOCALGLOBALKEYSET-DRIVEN

Page 12: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Integrated Full-Text Searching

Storing Large Text Documents is on the rise

RDBMS – Not Equiped on their own to handle this.

Oracle Text

•SELECT * FROM MYTextDocuments •WHERE CONTAINS(text, ‘Oracle’, 1)

> 0

•SELECT * FROM MYProductCatalog • WHERE CATSEARCH(title, ‘Camera’, ‘order by price desc’) > 0

• SELECT * FROM MyRules • WHERE

MATCHES(query_string,:doc_text) > 0

SS Full-TEXT

• SELECT * FROM MYTextDocuments • WHERE CONTAINS(text,

‘“SQL Server”’)• SELECT * FROM MYTextDocuments •WHERE FREETEXT(text, ‘SQL Server’)

• 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;

Page 13: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Tools to Ease Development Cycles

Tools for Creating Queries

• Command Line•SQL *Plus for Oracle•SQLCMD for SQL Server

• Graphical User Interfaces•SQL *Plus for Oracle•SQL Server Management Studio

• Beyond the Integrated Tools•Visual Studio .NET•ToadSoft Toad•And others

Page 14: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Error Handling

Servers always raise the errorsT-SQL dealings

@@ErrorTRY..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 messages that are not severe. DB does not raise system errors.

11-16 Indicate 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 execution ceases. Error messages are written to the error log.

Page 15: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Query Optimization

Cost-Based Optimization

Execution Plans based on :

oAccess methodsoStatisticsoHints

Plans can be viewed with:Oracle Explain PlanSQL Server Execution Plan

Page 16: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Transaction Management

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 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

Make Explicit by using: BEGIN TRAN … COMMIT TRAN

or SET IMPLICIT_TRANSACTIONS ON

Page 17: Module 5: Data Access. Overview Introduce database components involved in data access Introduce concepts of Transact -SQL and Procedural SQL as tools.

Review

We examined various components of the relational engine that parses, optimizes, and executes database calls and fetches data

We learned about the different types of statements that constitute the Structured Query Language (SQL)

We were introduced to procedural SQL offered by Oracle and SQL Server

We learned that the cost-based optimizer in Oracle and SQL Server performs SQL optimization that can be superseded by hints from the user

We learned about the concepts of local and distributed transactions and the two-phase commit


Recommended