Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20.

Similar presentations


Presentation on theme: "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20."— Presentation transcript:

1 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20

2 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-2 Agenda Questions? 2 Quizzes 2 go –April 20 DP Chap 9 & 11, SQL Chap 11 –May 4 DP Chap Assignment 8 posted –Due April 13 –3 more assignments to Go –Lowest assignment score dropped Capstone progress report Due –Capstones projects and presentations are due May 12 at 10AM Today we will be discussing Managing Multi-user Databases with SQL server 2000

3 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-3 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server 2000 Part One Database Processing: Fundamentals, Design, and Implementation

4 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-4 Introduction SQL Server 2000 can be installed on: –Windows 2000 and Windows XP workstations –Windows 2000 Server and Windows Server 2003 There are two ways to create database, to insert data, and to modify its structure: –Use the GUI SQL Server Enterprise Manager –Write SQL statements and submit them to SQL Server via the SQL Query Analyzer utility Many SQL Server professionals choose to create structures via SQL then modify them with the graphical tools

5 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-5 View Ridge Gallery View Ridge Gallery is a small art gallery that has been in business for 30 years It sells contemporary European and North American fine art View Ridge has one owner, three salespeople, and two workers View Ridge owns all of the art that it sells; it holds no items on a consignment basis

6 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-6 Application Requirements View Ridge application requirements: –Track customers and their artist interests –Record gallery's purchases –Record customers' art purchases –List the artists and works that have appeared in the gallery –Report how fast an artist's works have sold and at what margin –Show current inventory in a Web page

7 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-7 View Ridge Gallery Database Design

8 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-8 The IDENTITY Keyword SQL Server supports the SQL-92 standard The IDENTITY keyword implements a new constraint for surrogate keys: –IDENTITY (m, n) creates a surrogate key with an Identity Seed of m and an Identity Increment of n: CREATE TABLE CUSTOMER( CustomerID int NOT NULL IDENTITY (1000,1), Name char(25)NOT NULL, CONSTRAINT CustomerPK RIMARY KEY (CustomerID), CONSTRAINT CustomerAK1 UNIQUE (Name) );

9 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-9 SQL Server Enterprise Manager Right-Click Databases, then use New Database… to create a new database

10 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-10 Creating a Database Type in the new database name, and then click the OK button.

11 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-11

12 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-12 SQL Query Analyzer: Starting SQL Query Analyzer from Enterprise Manager Use the menu command Tools | SQL Query Analyzer.

13 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-13 SQL Query Analyzer: Creating the TRANS table in SQL Query Analyzer Use the Execute Query button after the SQL command is entered. Enter the SQL command in this window. Results appear in this window.

14 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-14 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Eleven Part One

15 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-15 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server 2000 Part Two Database Processing: Fundamentals, Design, and Implementation

16 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-16 SQL Server CREATE TABLE Statements for the View Ridge Schema

17 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-17 SQL Server CREATE TABLE Statements for the View Ridge Schema

18 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-18 SQL Server CREATE TABLE Statements for the View Ridge Schema

19 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-19 SQL Server CREATE TABLE Statements for the View Ridge Schema

20 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-20 Viewing Tables in Enterprise Manager Right-Click the table name, then click Design Table to view table columns and properties.

21 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-21 Viewing Table Columns and Properties in Enterprise Manager Right-click the white space and then click Properties to see table constraints.

22 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-22 Viewing Table Constraints in Enterprise Manager

23 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-23 Creating a Relationship Diagram in Enterprise Manager Right-click Diagrams, then click New Database Diagram to create a relationships diagram.

24 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-24 Table Relationship Diagram Right-click a relationship line, then click Properties to see the properties.

25 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-25 WORK – TRANS Relationship Properties

26 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-26 Creating Views: By SQL in SQL Query Analyzer Do NOT put a semi-colon (;) at the end of a CREATE VIEW statement in SQL Query Analyzer!

27 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-27 Creating Views: By GUI in Enterprise Manager

28 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-28 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Eleven Part Two

29 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-29 David M. Kroenke’s Chapter Eleven: Managing Databases with SQL Server 2000 Part Three Database Processing: Fundamentals, Design, and Implementation

30 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-30 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

31 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-31 Indexes 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

32 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-32 Creating an Index: By GUI in Enterprise Manager

33 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-33 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

34 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-34 Stored Procedures A stored procedure is a TRANSACT/SQL (T/SQL) complied program stored within the database: –T/SQL surrounds basic SQL statements with programming constructs such as parameters, variables, and logic structures such as IF and WHILE. Stored procedures are programs that can: –Have parameters –Invoke other procedures and functions –Return values –Raise exceptions Creating stored procedures –Write a stored procedure in a text file and process the commands using the Query Analyzer, or –Using Enterprise Manager

35 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-35 Variables are declared after the keyword AS Parameters

36 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-36

37 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-37 Triggers An SQL Server trigger is a T/SQL procedure that is invoked when a specified database activity occurs Triggers can be used to: –Enforce business rules –Set complex default values –Update views –Implement referential integrity actions SQL Server only supports INSTEAD OF and AFTER triggers: –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

38 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-38 This is an AFTER trigger on INSERT on the table TRANS. It is will set a default value on AskingPrice.

39 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-39 Triggers: Enforcing a Required Child Constraint There is an M-M relationship between WORK and TRANSACTION:

40 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-40 Triggers: Enforcing a Required Child Constraint The hard way using two triggers – this one enforces the required child:

41 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-41 Triggers: Enforcing a Required Child Constraint The hard way using two triggers – this one deletes any duplicate transaction:

42 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-42 Triggers: Enforcing a Required Child Constraint CREATE VIEW Work_Trans AS SELECT Title, Description, Copy, ArtistID, DateAcquired, AcquisitionPrice FROMWORK W JOIN TRANS T ONW.WorkID = T.WorkID; A better way - Create the Work_Trans view:

43 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-43 Triggers: Enforcing a Required Child Constraint A better way using one trigger – this one works with the Work_Trans view:

44 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-44 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

45 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-45 SQL Server Concurrency Options

46 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-46 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

47 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-47 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

48 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-48 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

49 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-49 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

50 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-50 David M. Kroenke’s Database Processing Fundamentals, Design, and Implementation (10 th Edition) End of Presentation: Chapter Eleven Part Three


Download ppt "DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-1 COS 346 Day 20."

Similar presentations


Ads by Google