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

Similar presentations


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

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

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 12 - 15 Assignment 8 posted –Due Today –3 more assignments to Go –Lowest assignment score dropped 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 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

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

5 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-5 Examples SET TRANSCATION LEVEL REPEATABLE READS; DECLARE MY_CURSOR DYNAMIC SCROLL_LOCK SELECT * FROM TABLE WITH HOLDLOCK:

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

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

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

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

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

11 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-11 Chapter 11: SQL Server Database Administration SQL for SQL Server Bijoy Bordoloi and Douglas Bock

12 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-12 Objectives Develop a general understanding of database administration. Understand the duties of a database administrator. Learn about the organization of a SQL Server database file structure. Create a database. Learn concepts concerning the SQL Server system catalog and database catalogs. Learn about the special dbo database user account. Become familiarized with the Enterprise Manager software. Create system and database user accounts. Grant, deny, and revoke permissions. Create and allocate roles.

13 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-13 Database administration is a specialized area within a large information systems department. A database administrator (DBA) works closely with application developers to support application development efforts. Database Administration Overview

14 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-14 Database Administrator Duties Install database management system software and upgrades. Design and create a database including the allocation of system disk storage for current and future database storage requirements. Start up and shut down database services. Create user accounts and monitor user activities. Grant database permissions to control data security and data access. Backup and recover a database in the event of system failure. Tune a database to optimize database performance. Manage database network connectivity. Migrate a database to a new version of the DBMS software.

15 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-15 Enterprise Manager SQL Server 2000’s Enterprise Manager software is a Microsoft Management Console snap-in. Enterprise Manager provides a graphical user interface for administering SQL Server databases. Use it to: –Create databases. –Create tables and other objects. –Create and manage user accounts. –Allocate system and object permissions. –Manage security and schedule tasks. –Perform database backups.

16 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-16 Enterprise Manager Graphical User Interface The initial window in unexpanded Tree view.

17 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-17 Expanded Tree Pane – Company Database

18 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-18 Database Types Two groups of databases were displayed on the previous slide: –(1) System databases – includes Master, Model, MSDB, and Tempdb. –(2) User-Defined Application databases. Those shown include the Company and Riverbend databases used in this textbook and two databases provided by Microsoft as examples – Northwind and Pubs.

19 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-19 System Databases Master – stores database information about other databases for a given instance of the SQL Server 2000. Also tracks disk space usage, configuration of the DBMS, and information on database objects. Model – a database template that is copied whenever you create a new database. Tempdb --- stores temporary objects/data such as those created by ORDER BY and JOIN operations. MSDB – used to schedule tasks such as database backup.

20 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-20 Database Files Physical windows files – includes a primary data file and transaction log file as a minimum. Primary data file – stores application data and startup information. Transaction log files – stores transaction data to support database recovery. Secondary data files – stores application data that will not fit into the primary data file – generally added to additional disk drives.

21 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-21 Database Files Contd.

22 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-22 Disk Storage Database objects are stored using two units of storage – page and extent. Database files are divided into pages while several pages are grouped into extents. Pages are 8Kb in size. A data row cannot span pages in SQL Server – the maximum row size is 8,060 bytes. Data pages store table row data; Index pages store index values; Text/Image pages store data of type TEXT, NTEXT, and IMAGE. Extents are contiguous pages allocated with 8 pages/extent.

23 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-23 Creating an SQL Server Database The CREATE DATABASE statement can be used with SQL Query Analyzer to create a database. Enterprise Manager is easier to use – right-click the database node or use the Action menu - New Database option.

24 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-24 Database Properties – General Tab

25 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-25 Database Properties – Data Files Tab Contd.

26 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-26 Database Properties – Data Files Tab The Database Properties dialog box – Data Files tab is used to specify file names for the primary data file. The example shown on the next slide is named TestDatabase_Data. It is stored to a folder named C:\Data. The data file has an initial size of 1Mb and is set to automatically grow in 10% increments.

27 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-27 Database Properties – Transaction Log Tab The figure shown on the next slide is the Transaction Log tab used to specify file names for the transaction log file. Here the transaction log is named TestDatabase_Log on drive C: in the folder named C:\DataLogs.

28 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-28 Database Properties – Transaction Log Tab Contd.

29 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-29 Files and File Groups Larger databases with several secondary data files are easier to manage by defining a filegroup object type – a logical container to hold files as a unit. This makes it easier to backup files. Use Enterprise Manager to create a filegroup by a right-click of the database in the Tree panel and selection of the Properties menu.

30 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-30 Files and File Groups Contd. Select the Filegroups tab and name the filegroup. You can then use the Properties dialog box to create secondary files and assign them to the filegroup.

31 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-31 Create Database Options to Create Filegroups The example shown here creates a primary data file along with a filegroup and secondary data files and log files. /* SQL Example 11.1 */ CREATE DATABASE TestDatabase ON PRIMARY ( NAME = TestDatabase_Data, FILENAME = 'C:\Data\TestDatabase_Data.Mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 25% ), FILEGROUP TestDatabaseGroup1 ( NAME = TestDatabaseSecondary1_Data, FILENAME = 'D:\Data\TestDatabaseSecondary1_Data.Ndf', SIZE = 20, MAXSIZE = 50, FILEGROWTH = 5% ),

32 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-32 Create Database Options to Create Filegroups Contd. ( NAME = TestDatabaseSecondary2_Data, FILENAME = 'E:\Data\TestDatabaseSecondary2_Data.Ndf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5% ) LOG ON ( NAME = 'TestDatabase_Log', FILENAME = 'G:\Datalogs\TestDatabase_Log.Ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB );

33 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-33 SQL Server System Catalog The SQL Server system catalog consists of system tables in the Master database. System tables stored in individual databases are the database catalog. The system catalog stores information about the structure of database objects such as databases, tables, views, and indexes – termed metadata (data about data). Only SQL Server should modify the system catalog.

34 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-34 SQL Server and Database Accounts Both SQL Query Analyzer and Enterprise Manager can create SQL Server login accounts. Within SQL Query Analyzer, you can execute several different procedures to create logins and to modify passwords. /* SQL Example Creating a Login */ EXEC sp_addlogin ‘thumb’, ‘secret’, ‘Company’; /* Changing password */ EXEC sp_password ‘secret’, ‘newsecret’, ‘thumb’;

35 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-35 Using Enterprise Manager to Create Login Accounts Select Tools menu, Wizards option and expand the Database tree. Select the Create Login Wizard option shown here.

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

37 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-37 Creating Login Accounts – Contd.

38 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-38 Creating Login Accounts – Contd.

39 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-39 Default Database User Accounts Users needing access to specific application databases must have a valid database user account for that database. Each database has two default accounts: dbo and guest. The dbo account owns a database and the account cannot be dropped. The guest account is used by users who have no specific database user account.

40 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-40 Creating Database User Accounts The sp_grantdbaccess procedure can be executed within SQL Query Analyzer to create a database user account and associate it with an existing Windows users account or SQL Server security login account. This example associates a database user account named robertsmith with a Windows user account named rsmith. EXEC sp_grantdbaccess ‘rsmith’, ‘robertsmith’ EXEC sp_grantdbaccess ‘rsmith’

41 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-41 Creating Database User Accounts Contd. Enterprise Manager can be used as shown here to create database user accounts. Expand the database tree and select New Database user – use the dialog box to enter the login and user name and grant permissions to the user.

42 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-42 Revoking Database User Accounts Through Enterprise Manager

43 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-43 Roles Roles make it easier for a DBA to manage the allocation of permissions. A role is like a container of a group of permissions for a specific type of system user such as an accountant. Each accountant hired will be authorized the permissions contained in the role named Accountant. This also applies to other jobs such as Clerk.

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

45 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-45 Fixed Server Roles Fixed server roles exist at the server level external to databases. Several fixed server roles exist. These include: –Sysadmin – a role granted all permissions for SQL Server and associated with the system administrator (sa) login and dbo user. –DbCreator – a role with permission to create/modify databases. –DiskAdmin – permission to manage disk files. –Other fixed server roles also exist and are described in the chapter reading.

46 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-46 Allocating Fixed Server Roles – Enterprise Manager Expand the security folder and select the Server Roles option. Right-click the role as shown.

47 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-47 Allocating Fixed Server Roles – Enterprise Manager Contd. Click the Add button to display the Add Members window as shown and add the members desired and click OK.

48 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-48 Fixed Database Roles These roles exist for each database and are grouped according to purpose. They include: –Db_owner – users who perform most database activities. –Db_accessadmin – permission to add/remove users. –Db_datareader – SELECT permission on any database table/view. –Db_datawriter – Can run any DML statement on any database table/view. –Other roles exist as described in the chapter.

49 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-49 Application Roles These roles are used to allocate specific permissions for specific applications such as payroll or inventory management. Application roles are allocated to login sessions. Application roles require a password. While connected to an application role, the database user loses all other allocated permissions except those associated with the application role. /* Example */ EXEC sp_addapprole ‘payroll’, ‘payroll_password’

50 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-50 User-Defined Database Roles This is the more traditional use of roles – to allocate permissions to groups of users as was described earlier. Suppose a role named Clerk has several permissions needed by a newly hired clerk named dbock. This EXEC will create the Clerk role owned by bbordoloi. The role is then granted to dbock. /* Example Granting Role */ EXEC sp_addrole ‘clerk’, ‘bbordoloi’ EXEC sp_addrolemember ‘clerk’, ‘dbock’

51 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-51 Permissions Permissions authorize database users to perform various operations such as CREATE DATABASE and SELECT. Permissions are divided into two categories: statement and object.

52 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-52 Granting Statement Permissions Use the GRANT statement to grant permissions. Statement permissions include: –CREATE DATABASE –CREATE DEFAULT –CREATE FUNCTION –CREATE PROCEDURE –CREATE RULE –CREATE TABLE –CREATE VIEW –BACKUP DATABASE –BACKUP LOG

53 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-53 Granting Statement Permissions – Contd. Grant all permissions to dbock. GRANT ALL TO dbock; Grant two permissions to tthumb and bbordoloi GRANT CREATE TABLE, CREATE VIEW TO tthumb, bbordol; Grant permissions to a role. GRANT CREATE PROCEDURE, CREATE FUNCTION TO clerk;

54 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-54 Granting Object Permissions Contd. Object permissions apply to a specific database object such as a table. Permissions include SELECT, UPDATE, INSERT, DELETE, and other object manipulations.

55 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-55 Granting Object Permissions Contd. General form of the GRANT statement: GRANT [ALL | permission_list] ON [table/view [column_list] | procedure] TO account_list [WITH GRANT OPTION] [AS {group_name | role_name}] The object is specified with the ON clause. The TO clause specifies who receives the permission. The WITH GRANT OPTION enables the grantee to grant the permission to others.

56 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-56 Granting Object Permissions – Contd. Grant SELECT on the dependent table. GRANT SELECT ON dependent TO bbordoloi; Grant SELECT and DELETE on the dependent table. GRANT SELECT, DELETE ON dependent TO dbock; Grant UPDATE on specific table columns. GRANT UPDATE ON dependent( dep_name, dep_gender) TO bbordoloi; Grant ALL permissions to everyone (PUBLIC). GRANT ALL ON dependent TO PUBLIC;

57 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-57 Granting Object Permissions – Enterprise Manager

58 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-58 Denying Permissions Denying permissions removes existing permissions from a database user account or role and prevents granting the permission to the database user account by accident through any other defined role. /* Examples */ DENY CREATE TABLE TO tthumb; DENY SELECT, UPDATE ON dependent TO dbock;

59 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-59 Revoking Permissions You can revoke both statement and object permissions. Permissions that are revoked can later be allocated again. /* Examples */ REVOKE SELECT ON dependent FROM PUBLIC; REVOKE UPDATE ON dependent FROM dbock; You can also revoke GRANT options and cause system users who have been granted permissions by a specific database user to also lose their permissions through the CASCADE clause. REVOKE GRANT OPTION FOR DELETE ON dependent FROM dbock CASCADE;

60 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-60 System Procedures System procedures such as the sp_help procedure can be used to display information about database objects. /* SQL Example 11.25 */ EXEC sp_help dependent Name Owner Type ---------- ---------- ------------- dependent dbo user table Column_name Type Computed Length ----------------- ---------- -------- -------- dep_emp_ssn char no 9 dep_name varchar no 50 dep_gender char no 1 other information is also listed...

61 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-61 System Procedures – Cont. Other system procedures such as sp_depends can display dependency information among objects such as tables and views. This example shows dependency information for the employee table. /* SQL Example 11.26 */ EXEC sp_depends employee; In the current database, the specified object is referenced by the following: Name type ----------------- ---------------- dbo.ck_emp_salary check cns

62 DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 9-62 Summary A SQL Server installation is managed through the Enterprise Manager. A SQL Server database includes physical and logical objects such as files and filegroups. The system catalog stores metadata for a SQL Server instance and all databases. Each database has a database catalog. You learned to create SQL Server login accounts, database accounts, and roles. You also learned to allocate, deny, and revoke system and object permissions to/from accounts and roles.


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

Similar presentations


Ads by Google