Tải bản đầy đủ (.pdf) (748 trang)

sql all-in-one for dummies 2nd edition

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (20.09 MB, 748 trang )

8

IN
1
BOOKS
BOOKS
• SQL Concepts
• Relational Database Development
• SQL Queries
• Data Security
• SQL and Programming
• SQL and XML
• Database Tuning Overview
• Appendices
Allen G. Taylor
SQL
ALL-IN-ONE
Making Everything Easier!

























































2nd Edition

www.it-ebooks.info
Start with FREE Cheat Sheets
Cheat Sheets include
• Checklists
• Charts
• Common Instructions
• And Other Good Stuff!
Get Smart at Dummies.com
Dummies.com makes your life easier with 1,000s
of answers on everything from removing wallpaper
to using the latest version of Windows.
Check out our
• Videos
• Illustrated Articles
• Step-by-Step Instructions
Plus, each month you can win valuable prizes by entering

our Dummies.com sweepstakes. *
Want a weekly dose of Dummies? Sign up for Newsletters on
• Digital Photography
• Microsoft Windows & Office
• Personal Finance & Investing
• Health & Wellness
• Computing, iPods & Cell Phones
• eBay
• Internet
• Food, Home & Garden
Find out “HOW” at Dummies.com
*Sweepstakes not currently available in all countries; visit Dummies.com for official rules.
Get More and Do More at Dummies.com
®
To access the Cheat Sheet created specifically for this book, go to
www.dummies.com/cheatsheet/sqlaio











www.it-ebooks.info
SQL
ALL-IN-ONE

FOR
DUMmIES

2ND EDITION


www.it-ebooks.info

www.it-ebooks.info
by Allen G. Taylor
SQL
ALL-IN-ONE
FOR
DUMmIES

2ND EDITION

www.it-ebooks.info
SQL All-in-One For Dummies
®
, 2nd Edition
Published by
Wiley Publishing, Inc.
111 River Street
Hoboken, NJ 07030-5774
www.wiley.com
Copyright © 2011 by Wiley Publishing, Inc., Indianapolis, Indiana
Published by Wiley Publishing, Inc., Indianapolis, Indiana
Published simultaneously in Canada
No part of this publication may be reproduced, stored in a retrieval system or transmitted in any form or

by any means, electronic, mechanical, photocopying, recording, scanning or otherwise, except as permit-
ted under Sections 107 or 108 of the 1976 United States Copyright Act, without either the prior written
permission of the Publisher, or authorization through payment of the appropriate per-copy fee to the
Copyright Clearance Center, 222 Rosewood Drive, Danvers, MA 01923, (978) 750-8400, fax (978) 646-8600.
Requests to the Publisher for permission should be addressed to the Permissions Department, John Wiley
& Sons, Inc., 111 River Street, Hoboken, NJ 07030, (201) 748-6011, fax (201) 748-6008, or online at http://
www.wiley.com/go/permissions.
Trademarks: Wiley, the Wiley Publishing logo, For Dummies, the Dummies Man logo, A Reference for the
Rest of Us!, The Dummies Way, Dummies Daily, The Fun and Easy Way, Dummies.com, Making Everything
Easier,
and related trade dress are trademarks or registered trademarks of John Wiley & Sons, Inc. and/
or its af liates in the United States and other countries, and may not be used without written permission.
All other trademarks are the property of their respective owners. Wiley Publishing, Inc., is not associated
with any product or vendor mentioned in this book.
LIMIT OF LIABILITY/DISCLAIMER OF WARRANTY: THE PUBLISHER AND THE AUTHOR MAKE NO
REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE ACCURACY OR COMPLETENESS OF
THE CONTENTS OF THIS WORK AND SPECIFICALLY DISCLAIM ALL WARRANTIES, INCLUDING WITH-
OUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE. NO WARRANTY MAY BE
CREATED OR EXTENDED BY SALES OR PROMOTIONAL MATERIALS. THE ADVICE AND STRATEGIES
CONTAINED HEREIN MAY NOT BE SUITABLE FOR EVERY SITUATION. THIS WORK IS SOLD WITH THE
UNDERSTANDING THAT THE PUBLISHER IS NOT ENGAGED IN RENDERING LEGAL, ACCOUNTING, OR
OTHER PROFESSIONAL SERVICES. IF PROFESSIONAL ASSISTANCE IS REQUIRED, THE SERVICES OF
A COMPETENT PROFESSIONAL PERSON SHOULD BE SOUGHT. NEITHER THE PUBLISHER NOR THE
AUTHOR SHALL BE LIABLE FOR DAMAGES ARISING HEREFROM. THE FACT THAT AN ORGANIZA-
TION OR WEBSITE IS REFERRED TO IN THIS WORK AS A CITATION AND/OR A POTENTIAL SOURCE
OF FURTHER INFORMATION DOES NOT MEAN THAT THE AUTHOR OR THE PUBLISHER ENDORSES
THE INFORMATION THE ORGANIZATION OR WEBSITE MAY PROVIDE OR RECOMMENDATIONS IT
MAY MAKE. FURTHER, READERS SHOULD BE AWARE THAT INTERNET WEBSITES LISTED IN THIS
WORK MAY HAVE CHANGED OR DISAPPEARED BETWEEN WHEN THIS WORK WAS WRITTEN AND
WHEN IT IS READ.

For general information on our other products and services, please contact our Customer Care
Department within the U.S. at 877-762-2974, outside the U.S. at 317-572-3993, or fax 317-572-4002.
For technical support, please visit www.wiley.com/techsupport.
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print may
not be available in electronic books.
Library of Congress Control Number: 2011922795
ISBN: 978-0-470-92996-4
Manufactured in the United States of America
10 9 8 7 6 5 4 3 2 1

www.it-ebooks.info
About the Author
Allen G. Taylor is a 30-year veteran of the computer industry and the
author of more than 25 books, including SQL For Dummies, Crystal Reports
2008 For Dummies, Database Development For Dummies, Access 2003
Power Programming with VBA, and SQL Weekend Crash Course. He lectures
internationally on databases, networks, innovation, astronomy and entre-
preneurship. He also teaches database development through a leading
online education provider. For the latest news on Allen’s activities, check
out both his blog (at www.moontube.wordpress.com) and his Web site
(at www.DatabaseCentral.Info). You can contact Allen at allen.


www.it-ebooks.info

www.it-ebooks.info
Dedication
This book is dedicated to Joyce Carolyn Taylor, my partner in life.

www.it-ebooks.info


www.it-ebooks.info
Author’s Acknowledgments
First and foremost, I would like to acknowledge the help of Jim Melton,
editor of the ISO/ANSI speci cation for SQL. Without his untiring efforts, this
book — and indeed SQL itself as an international standard — would be of
much less value. Andrew Eisenberg has also contributed to my knowledge
of SQL through his writing. I would also like to thank my project editor,
Paul Levesque, and my acquisitions editor, Kyle Looper, for their key con-
tributions to the production of this book. Thanks also to my agent, Carole
McClendon of Waterside Productions, for her support of my career.

www.it-ebooks.info

Publisher’s Acknowledgments
We’re proud of this book; please send us your comments at . For
other comments, please contact our Customer Care Department within the U.S. at 877-762-2974, out-
side the U.S. at 317-572-3993, or fax 317-572-4002.
Some of the people who helped bring this book to market include the following:
Acquisitions and Editorial
Senior Project Editor: Paul Levesque
Acquisitions Editor: Kyle Looper
Copy Editors: Kathy Simpson
Technical Editor: Robert Schneider
Editorial Manager: Leah Cameron
Editorial Assistant: Amanda Graham
Sr. Editorial Assistant: Cherie Case
Cartoons:
Rich Tennant (www.the5thwave.com)
Composition Services

Project Coordinator: Patrick Redmond
Layout and Graphics: Joyce Haughey,
Corrie Socolovitch
Proofreader: Evelyn Wellborn
Indexer: BIM Indexing & Proofreading Services
Publishing and Editorial for Technology Dummies
Richard Swadley, Vice President and Executive Group Publisher
Andy Cummings, Vice President and Publisher
Mary Bednarek, Executive Acquisitions Director
Mary C. Corder, Editorial Director
Publishing for Consumer Dummies
Diane Graves Steele, Vice President and Publisher
Composition Services
Debbie Stailey, Director of Composition Services

www.it-ebooks.info
Contents at a Glance
Introduction 1
Book I: SQL Concepts 7
Chapter 1: Understanding Relational Databases 9
Chapter 2: Modeling a System 29
Chapter 3: Getting to Know SQL 51
Chapter 4: SQL and the Relational Model 63
Chapter 5: Knowing the Major Components of SQL 73
Chapter 6: Drilling Down to the SQL Nitty-Gritty 95
Book II: Relational Database Development 125
Chapter 1: System Development Overview 127
Chapter 2: Building a Database Model 143
Chapter 3: Balancing Performance and Correctness 161
Chapter 4: Creating a Database with SQL 193

Book III: SQL Queries 205
Chapter 1: Values, Variables, Functions, and Expressions 207
Chapter 2: SELECT Statements and Modifying Clauses 231
Chapter 3: Querying Multiple Tables with Subqueries 275
Chapter 4: Querying Multiple Tables with Relational Operators 303
Chapter 5: Cursors 323
Book IV: Data Security 335
Chapter 1: Protecting Against Hardware Failure and External Threats 337
Chapter 2: Protecting Against User Errors and Con icts 367
Chapter 3: Assigning Access Privileges 395
Chapter 4: Error Handling 407
Book V: SQL and Programming 423
Chapter 1: Database Development Environments 425
Chapter 2: Interfacing SQL to a Procedural Language 431
Chapter 3: Using SQL in an Application Program 437
Chapter 4: Designing a Sample Application 451

www.it-ebooks.info
Chapter 5: Building an Application 469
Chapter 6: Understanding SQL’s Procedural Capabilities 485
Chapter 7: Connecting SQL to a Remote Database 501
Book VI: SQL and XML 515
Chapter 1: Using XML with SQL 517
Chapter 2: Storing XML Data in SQL Tables 541
Chapter 3: Retrieving Data from XML Documents 561
Book VII: Database Tuning Overview 577
Chapter 1: Tuning the Database 579
Chapter 2: Tuning the Environment 591
Chapter 3: Finding and Eliminating Bottlenecks 611
Book VIII: Appendices 641

Appendix A: SQL:2008 Reserved Words 643
Appendix B: Glossary 651
Index 661

www.it-ebooks.info
Table of Contents
Introduction 1
About This Book 1
Foolish Assumptions 2
Conventions Used in This Book 2
What You Don’t Have to Read 3
How This Book Is Organized 3
Book I: SQL Concepts 3
Book II: Relational Database Development 3
Book III: SQL Queries 4
Book IV: Data Security 4
Book V: SQL and Programming 4
Book VI: SQL and XML 4
Book VII: Database Tuning Overview 5
Book VIII: Appendices 5
Icons Used in This Book 5
Where to Go from Here 6
Book I: SQL Concepts 7
Chapter 1: Understanding Relational Databases . . . . . . . . . . . . . . . . . . .9
Understanding Why Today’s Databases Are Better
Than Early Databases 9
Irreducible complexity 10
Managing data with complicated programs 10
Managing data with simple programs 12
Which type of organization is better? 13

Databases, Queries, and Database Applications 13
Making data useful 13
Retrieving the data you want — and only the data you want 14
Examining Competing Database Models 15
Looking at the historical background
of the competing models 15
The hierarchical database model 16
The network database model 20
The relational database model 20
De ning what makes a database relational 22
Protecting the de nition of relational databases
with Codd’s Rules 22
Highlighting the relational database model’s
inherent  exibility 25

www.it-ebooks.info
SQL All-in-One For Dummies, 2nd Edition
xiv
The object-oriented database model 25
The object-relational database model 25
The nonrelational NoSQL model 26
Why the Relational Model Won 26
Chapter 2: Modeling a System. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Capturing the Users’ Data Model 29
Identifying and interviewing stakeholders 30
Reconciling con icting requirements 30
Obtaining stakeholder buy-in 31
Translating the Users’ Data Model to a Formal
Entity-Relationship Model 32
Entity-Relationship modeling techniques 32

Entities 33
Attributes 33
Identi ers 34
Relationships 35
Drawing Entity-Relationship diagrams 38
Maximum cardinality 38
Minimum cardinality 38
Understanding advanced ER model concepts 41
Strong entities and weak entities 41
ID-dependent entities 42
Supertype and subtype entities 43
Incorporating business rules 44
A simple example of an ER model 45
A slightly more complex example 46
Problems with complex relationships 50
Simplifying relationships using normalization 50
Translating an ER model into a relational model 50
Chapter 3: Getting to Know SQL. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
Where SQL Came From 51
Knowing What SQL Does 52
The ISO/IEC SQL Standard 53
Knowing What SQL Does Not Do 53
Choosing and Using an Available DBMS Implementation 54
Microsoft Access 55
Microsoft SQL Server 59
IBM DB2 59
Oracle Database 59
Sybase SQL Anywhere 60
MySQL 60
PostgreSQL 61


www.it-ebooks.info
Table of Contents
xv
Chapter 4: SQL and the Relational Model . . . . . . . . . . . . . . . . . . . . . . . .63
Sets, Relations, Multisets, and Tables 63
Functional Dependencies 64
Keys 65
Views 67
Users 68
Privileges 68
Schemas 68
Catalogs 69
Connections, Sessions, and Transactions 69
Routines 70
Paths 71
Chapter 5: Knowing the Major Components of SQL. . . . . . . . . . . . . . . .73
Creating a Database with the Data De nition Language 73
The containment hierarchy 74
Creating tables 75
Specifying columns 75
Creating other objects 75
Views 76
Schemas 80
Domains 81
Modifying tables 82
Removing tables and other objects 82
Operating on Data with the Data Manipulation Language (DML) 83
Retrieving data from a database 83
Adding data to a table 84

Adding data the dull and boring way (typing it in) 84
Adding incomplete records 85
Adding data in the fastest and most ef cient way:
Bypassing typing altogether 86
Updating data in a table 87
Deleting data from a table 90
Updating views doesn’t make sense 91
Maintaining Security in the Data Control Language (DCL) 92
Granting access privileges 92
Revoking access privileges 93
Preserving database integrity with transactions 93
Chapter 6: Drilling Down to the SQL Nitty-Gritty . . . . . . . . . . . . . . . . . .95
Executing SQL Statements 95
Interactive SQL 96
Challenges to combining SQL with a host language 96
Embedded SQL 97
Module language 99
Using Reserved Words Correctly 100

www.it-ebooks.info
SQL All-in-One For Dummies, 2nd Edition
xvi
SQL’s Data Types 100
Exact numerics 101
INTEGER 101
SMALLINT 102
BIGINT 102
NUMERIC 103
DECIMAL 103
Approximate numerics 103

REAL 104
DOUBLE PRECISION 104
FLOAT 104
Character strings 105
CHARACTER 105
CHARACTER VARYING 105
CHARACTER LARGE OBJECT (CLOB) 105
NATIONAL CHARACTER, NATIONAL CHARACTER
VARYING, and NATIONAL CHARACTER
LARGE OBJECT 106
Binary strings 106
BINARY 107
BINARY VARYING 107
BINARY LARGE OBJECT (BLOB) 107
Booleans 107
Datetimes 107
DATE 108
TIME WITHOUT TIME ZONE 108
TIME WITH TIME ZONE 108
TIMESTAMP WITHOUT TIME ZONE 109
TIMESTAMP WITH TIME ZONE 109
Intervals 109
XML type 110
ROW type 110
Collection types 111
ARRAY 112
Multiset 112
REF types 113
User-de ned types 113
Distinct types 114

Structured types 114
Data type summary 116
Handling Null Values 117
Applying Constraints 118
Column constraints 118
NOT NULL 119
UNIQUE 119
CHECK 119
Table constraints 120
Foreign key constraints 121
Assertions 123

www.it-ebooks.info
Table of Contents
xvii
Book II: Relational Database Development 125
Chapter 1: System Development Overview . . . . . . . . . . . . . . . . . . . . . .127
The Components of a Database System 127
The database 128
The database engine 128
The DBMS front end 128
The database application 129
The user 129
The System Development Life Cycle 129
De nition phase 130
Requirements phase 131
The users’ data model 132
Statement of Requirements 133
Evaluation phase 133
Determining project scope 134

Reassessing feasibility 135
Documenting the Evaluation phase 136
Design phase 136
Designing the database 136
The database application 137
Documenting the Design phase 138
Implementation phase 138
Final Documentation and Testing phase 139
Testing the system with sample data 139
Finalizing the documentation 140
Delivering the results (and celebrating) 140
Maintenance phase 141
Chapter 2: Building a Database Model . . . . . . . . . . . . . . . . . . . . . . . . .143
Finding and Listening to Interested Parties 143
Your immediate supervisor 144
The users 144
The standards organization 145
Upper management 146
Building Consensus 146
Gauging what people want 147
Arriving at a consensus 147
Building a Relational Model 148
Reviewing the three database traditions 148
Knowing what a relation is 149
Functional dependencies 150
Keys 151
Being Aware of the Danger of Anomalies 151
Eliminating anomalies 152
Examining the higher normal forms 156
The Database Integrity versus Performance Tradeoff 157


www.it-ebooks.info
SQL All-in-One For Dummies, 2nd Edition
xviii
Chapter 3: Balancing Performance and Correctness . . . . . . . . . . . . .161
Designing a Sample Database 162
The ER model for Honest Abe’s 162
Converting an ER model into a relational model 163
Normalizing a relational model 164
Handling binary relationships 166
A sample conversion 171
Maintaining Integrity 174
Entity integrity 174
Domain integrity 175
Referential integrity 176
Avoiding Data Corruption 177
Speeding Data Retrievals 179
Hierarchical storage 179
Full table scans 180
Working with Indexes 181
Creating the right indexes 181
Indexes and the ANSI/ISO Standard 182
Index costs 182
Query type dictates the best index 182
Point query 182
Multipoint query 182
Range query 183
Pre x match query 183
Extremal query 183
Ordering query 183

Grouping query 184
Equi-join query 184
Data structures used for indexes 184
Indexes, sparse and dense 185
Index clustering 186
Composite indexes 186
Index effect on join performance 187
Table size as an indexing consideration 187
Indexes versus full table scans 187
Reading SQL Server Execution Plans 188
Robust execution plans 188
A sample database 189
A typical query 190
The execution plan 190
Running the Database Engine Tuning Advisor 191
Chapter 4: Creating a Database with SQL . . . . . . . . . . . . . . . . . . . . . . .193
First Things First: Planning Your Database 193
Building Tables 194
Locating table rows with keys 195
Using the CREATE TABLE statement 196

www.it-ebooks.info
Table of Contents
xix
Setting Constraints 198
Column constraints 198
Table constraints 198
Keys and Indexes 198
Ensuring Data Validity with Domains 199
Establishing Relationships between Tables 199

Altering Table Structure 202
Deleting Tables 203
Book III: SQL Queries 205
Chapter 1: Values, Variables, Functions, and Expressions . . . . . . . .207
Entering Data Values 207
Row values have multiple parts 207
Identifying values in a column 208
Literal values don’t change 208
Variables vary 209
Special variables hold speci c values 210
Working with Functions 211
Summarizing data with set functions 211
COUNT 211
AVG 212
MAX 212
MIN 212
SUM 213
Dissecting data with value functions 213
String value functions 213
Numeric value functions 215
Datetime value functions 220
Using Expressions 221
Numeric value expressions 221
String value expressions 221
Datetime value expressions 222
Interval value expressions 223
Boolean value expressions 224
Array value expressions 224
Conditional value expressions 224
Handling different cases 225

The NULLIF special CASE 226
Bypassing null values with COALESCE 227
Converting data types with a CAST expression 227
Casting one SQL data type to another 228
Using CAST to overcome data type incompatibilities
between SQL and its host language 228
Row value expressions 229

www.it-ebooks.info
SQL All-in-One For Dummies, 2nd Edition
xx
Chapter 2: SELECT Statements and Modifying Clauses . . . . . . . . . . .231
Finding Needles in Haystacks with the SELECT Statement 231
Modifying Clauses 232
FROM clauses 232
WHERE clauses 233
Comparison predicates 234
BETWEEN 235
IN and NOT IN 236
LIKE and NOT LIKE 237
SIMILAR 239
NULL 239
ALL, SOME, and ANY 240
EXISTS 243
UNIQUE 243
DISTINCT 244
OVERLAPS 244
MATCH 245
The MATCH predicate and referential integrity 246
Logical connectives 248

GROUP BY clauses 250
HAVING clauses 252
ORDER BY clauses 253
Tuning Queries 255
SELECT DISTINCT 255
Query analysis provided by SQL Server 2008 R2 256
Query analysis provided by MySQL 5 258
Temporary tables 259
The ORDER BY clause 265
The HAVING clause 268
The OR logical connective 272
Chapter 3: Querying Multiple Tables with Subqueries. . . . . . . . . . . .275
What Is a Subquery? 275
What Subqueries Do 275
Subqueries that return multiple values 276
Subqueries that retrieve rows satisfying a condition 276
Subqueries that retrieve rows that don’t satisfy
a condition 277
Subqueries that return a single value 278
Quanti ed subqueries return a single value 280
Correlated subqueries 283
Using a subquery as an existence test 283
Introducing a correlated subquery
with the IN keyword 284

www.it-ebooks.info
Table of Contents
xxi
Introducing a correlated subquery
with a comparison operator 285

Correlated subqueries in a HAVING clause 287
Using Subqueries in INSERT, DELETE, and UPDATE Statements 288
Tuning Considerations for Statements Containing Nested Queries 291
Tuning Correlated Subqueries 297
Chapter 4: Querying Multiple Tables with Relational Operators . . .303
UNION 303
UNION ALL 305
UNION CORRESPONDING 306
INTERSECT 306
EXCEPT 308
JOINS 308
Cartesian product or cross join 309
Equi-join 311
Natural join 313
Condition join 313
Column-name join 314
Inner join 315
Outer join 316
Left outer join 316
Right outer join 318
Full outer join 318
ON versus WHERE 319
Join Conditions and Clustering Indexes 320
Chapter 5: Cursors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .323
Declaring a Cursor 324
The query expression 325
Ordering the query result set 325
Updating table rows 327
Sensitive versus insensitive cursors 327
Scrolling a cursor 328

Holding a cursor 329
Declaring a result set cursor 329
Opening a Cursor 329
Operating on a Single Row 331
FETCH syntax 331
Absolute versus relative fetches 332
Deleting a row 332
Updating a row 332
Closing a Cursor 333

www.it-ebooks.info
SQL All-in-One For Dummies, 2nd Edition
xxii
Book IV: Data Security 335
Chapter 1: Protecting Against Hardware Failure and
External Threats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .337
What Could Possibly Go Wrong? 337
Equipment failure 338
Platform instability 339
Database design  aws 340
Data-entry errors 340
Operator error 340
Taking Advantage of RAID 341
Striping 341
RAID levels 342
RAID 0 344
RAID 1 344
RAID 5 344
RAID 10 345
Backing Up Your System 345

Preparation for the worst 345
Full or incremental backup 346
Frequency 346
Backup maintenance 347
Coping with Internet Threats 347
Viruses 348
Trojan horses 349
Worms 350
Denial-of-service attacks 351
SQL injection attacks 351
Chipping away at your wall of protection 351
Understanding SQL injection 351
Using a GET parameter 352
Recognizing unsafe con gurations 359
Finding vulnerabilities on your site 359
Phishing scams 362
Zombie spambots 363
Installing Layers of Protection 363
Network-layer  rewalls 364
Application-layer  rewalls 364
Antivirus software 364
Vulnerabilities, exploits, and patches 364
Education 365
Alertness 365

www.it-ebooks.info
Table of Contents
xxiii
Chapter 2: Protecting Against User Errors and Confl icts . . . . . . . . . .367
Reducing Data-Entry Errors 367

Data types: The  rst line of defense 368
Constraints: The second line of defense 368
Sharp-eyed humans: The third line of defense 368
Coping with Errors in Database Design 369
Handling Programming Errors 369
Solving Concurrent-Operation Con icts 370
Passing the ACID Test: Atomicity, Consistency, Isolation,
and Durability 371
Operating with Transactions 372
Using the SET TRANSACTION statement 372
Starting a transaction 373
Access modes 374
Isolation levels 374
Committing a transaction 376
Rolling back a transaction 376
Why roll back a transaction? 377
The log  le 377
The write-ahead log protocol 378
Checkpoints 379
Implementing deferrable constraints 379
Getting Familiar with Locking 383
Two-phase locking 384
Granularity 384
Deadlock 385
Tuning Locks 386
Measuring performance with throughput 386
Eliminating unneeded locks 387
Shortening transactions 387
Weakening isolation levels (ver-r-ry carefully) 387
Controlling lock granularity 388

Scheduling DDL statements correctly 388
Partitioning insertions 389
Cooling hot spots 389
Tuning the deadlock interval 389
Enforcing Serializability with Timestamps 390
Tuning the Recovery System 392
Chapter 3: Assigning Access Privileges . . . . . . . . . . . . . . . . . . . . . . . .395
Working with the SQL Data Control Language 395
Identifying Authorized Users 395
Understanding user identi ers 396
Creating roles 397
Destroying roles 397
Getting familiar with roles 396


www.it-ebooks.info

×