Download ch11_Kroenke9

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts

IMDb wikipedia , lookup

Entity–attribute–value model wikipedia , lookup

Serializability wikipedia , lookup

Tandem Computers wikipedia , lookup

Microsoft Access wikipedia , lookup

Team Foundation Server wikipedia , lookup

Oracle Database wikipedia , lookup

Navitaire Inc v Easyjet Airline Co. and BulletProof Technologies, Inc. wikipedia , lookup

Extensible Storage Engine wikipedia , lookup

Ingres (database) wikipedia , lookup

Btrieve wikipedia , lookup

Database wikipedia , lookup

Concurrency control wikipedia , lookup

Microsoft Jet Database Engine wikipedia , lookup

Database model wikipedia , lookup

Open Database Connectivity wikipedia , lookup

ContactPoint wikipedia , lookup

Relational model wikipedia , lookup

SQL wikipedia , lookup

Clusterpoint wikipedia , lookup

Microsoft SQL Server wikipedia , lookup

PL/SQL wikipedia , lookup

Transcript
Chapter 11
Managing Databases
with SQL Server 2000
Fundamentals, Design,
and Implementation, 9/e
Introduction
 SQL Server 2000 can be installed on Windows
2000 and Windows XP computers
 There are two ways to create database, to insert
data, and to modify its structure
– Use the Server Enterprise Manager, i.e., graphical design
tools similar to those in Microsoft Access
– Write SQL statements and submit them to SQL Server
via the SQL Query Analyzer utility
 Many professionals choose to create structures via
SQL, but to modify them with the graphical tools
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/2
Example: CREATE TABLE
statement
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/3
Example: Table Properties
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/4
IDENTITY Constraint
 SQL Server supports SQL-92 standard
 IDENTITY constraint is the only new
constraint
– IDENTITY (m, n) creates a surrogate key with an
Identity Seed of m and an Identity Increment of n
– Example:
CREATE TABLE CUSTOMER(
CustomerID int NOT NULL IDENTITY (1000,1),
Name char(25) NOT NULL,
CONSTRAINT CustomerPK PRIMARY KEY (CustomerID),
CONSTRAINT CustomerAK1 UNIQUE (Name));
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/5
Example: Relationship Diagram
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/6
Creating Views
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/7
Indexes
 Indexes are special data structures used to
improve database performance
 SQL Server automatically creates an index
on all primary and foreign keys
 Additional indexes may be assigned on
other columns that are
– Frequently used in WHERE clauses
– Used for sorting data
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/8
Indexes (cont.)
 SQL Server supports two kinds of indexes:
– Clustered index: the data are stored in the
bottom level of the index and in the same order
as that index
– Nonclustered index: the bottom level of an
index contains pointers to the data
 Clustered indexes are faster than
nonclustered indexes for updating and
retrieval
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/9
Application Logic
 SQL Server database application can be
processed using
– Programming language, e.g., C#, C++, Visual
Basic, Java, to invoke SQL Server DBMS
commands
– Stored procedures
– SQL Query Analyzer to invoke database
commands stored in .sql files
– Triggers
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/10
Stored Procedures
 With SQL Server 2000, stored procedures
must be written in TRANSACT/SQL, or
T/SQL
– T/SQL surrounds basic SQL statements with
programming constructs such as parameters,
variables, and logic structures such as IF and
WHILE
 Creating stored procedures
– Write a stored procedure in a text file and
process the commands using the Query
Analyzer
– Using Enterprise Manager
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/11
Triggers
 Triggers can be used to
–
–
–
–
Enforce business rules
Set complex default values
Update views
Implement referential integrity actions
 SQL Server supports INSTEAD OF and AFTER
triggers only
– A table may have one or more AFTER triggers
– AFTER triggers may not be assigned to views
– A view or table may have only one INSTEAD OF trigger
for each triggering action
 Triggers can roll back the transactions that caused
them to be fired
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/12
Concurrency Control
 Three factors determine the concurrency control
behavior of SQL Server
– Transaction isolation level
– Cursor concurrency setting
– Locking hints provided in the SELECT clause
 Locking behavior also changes, depending on
whether actions occur in the context of
transactions or cursors independently
– Therefore, SQL Server places locks on behalf of the
developer
– Locks may be placed at many levels of granularity and
may be promoted or demoted as work progresses
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/13
SQL Server Concurrency Options
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/14
SQL Server 2000 Security
 SQL server provides two modes of
authentication
– Windows only: the authentication is provided by
the windows operating system
– Mixed security: SQL Server will accept either
the windows-authenticated user name or it will
perform its own authentication
 Roles may be assigned to a SQL Server
user account
– A role is a group of predefined authorities
– Public role has the authority only to connect to
the database
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/15
SQL Server Backup
 SQL Server supports several types of
backup
– A complete backup makes a copy of the entire
database
– A differential backup makes a copy of the
database changes since the last complete
backup
• Differential backups are faster and can be taken more
frequently
• Complete backups are simpler to use for recovery
 The transaction log also needs to be
periodically backed up
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/16
Database Recovery
 Both data and log files are created by SQL Server
 SQL Server provides a wizard for setting up
database maintenance plan, e.g., scheduling
database and log backups
 To recover a database with SQL Server
– The database is restored from a prior database backup
– Log after images are applied to the restored database
– At the end of the log, changes from any transaction that
failed to commit are then rolled back
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/17
SQL Server Recovery Models
 Three recovery models
– Simple recovery: neither logging is done nor log
records applied
• To recover a database is to restore the database to
the last backup
• This method can be used for a database that is never
changed
– Full recovery: all database changes are logged
– Bulk-logged: all changes are logged except
those that cause large log entries
Copyright © 2004 Database Processing: Fundamentals, Design, and Implementation, 9/e
by David M. Kroenke
Chapter 11/18
Chapter 11
Managing Databases
with SQL Server 2000
Fundamentals, Design,
and Implementation, 9/e