Presentation is loading. Please wait.

Presentation is loading. Please wait.

Prentice Hall © 20041 Chapter 11: SQL Server Database Administration SQL for SQL Server Bijoy Bordoloi and Douglas Bock.

Similar presentations


Presentation on theme: "Prentice Hall © 20041 Chapter 11: SQL Server Database Administration SQL for SQL Server Bijoy Bordoloi and Douglas Bock."— Presentation transcript:

1 Prentice Hall © 20041 Chapter 11: SQL Server Database Administration SQL for SQL Server Bijoy Bordoloi and Douglas Bock

2 Prentice Hall © 20042 Objectives Develop a general understanding of database administration.Develop a general understanding of database administration. Understand the duties of a database administrator.Understand the duties of a database administrator. Learn about the organization of a SQL Server database file structure.Learn about the organization of a SQL Server database file structure. Create a database.Create a database. Learn concepts concerning the SQL Server system catalog and database catalogs.Learn concepts concerning the SQL Server system catalog and database catalogs. Learn about the special dbo database user account.Learn about the special dbo database user account. Become familiarized with the Enterprise Manager software.Become familiarized with the Enterprise Manager software. Create system and database user accounts.Create system and database user accounts. Grant, deny, and revoke permissions.Grant, deny, and revoke permissions. Create and allocate roles.Create and allocate roles.

3 Prentice Hall © 20043 Database administration is a specialized area within a large information systems department.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.A database administrator (DBA) works closely with application developers to support application development efforts. Database Administration Overview

4 Prentice Hall © 20044 Database Administrator Duties Install database management system software and upgrades.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.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.Start up and shut down database services. Create user accounts and monitor user activities.Create user accounts and monitor user activities. Grant database permissions to control data security and data access.Grant database permissions to control data security and data access. Backup and recover a database in the event of system failure.Backup and recover a database in the event of system failure. Tune a database to optimize database performance.Tune a database to optimize database performance. Manage database network connectivity.Manage database network connectivity. Migrate a database to a new version of the DBMS software.Migrate a database to a new version of the DBMS software.

5 Prentice Hall © 20045 Enterprise Manager SQL Server 2000’s Enterprise Manager software is a Microsoft Management Console snap-in.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: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.

6 Prentice Hall © 20046 Enterprise Manager Graphical User Interface The initial window in unexpanded Tree view.

7 Prentice Hall © 20047 Expanded Tree Pane – Company Database

8 Prentice Hall © 20048 Database Types Two groups of databases were displayed on the previous slide: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.

9 Prentice Hall © 20049 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.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.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.Tempdb --- stores temporary objects/data such as those created by ORDER BY and JOIN operations. MSDB – used to schedule tasks such as database backup.MSDB – used to schedule tasks such as database backup.

10 Prentice Hall © 200410 Database Files Physical windows files – includes a primary data file and transaction log file as a minimum.Physical windows files – includes a primary data file and transaction log file as a minimum. Primary data file – stores application data and startup information.Primary data file – stores application data and startup information. Transaction log files – stores transaction data to support database recovery.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.Secondary data files – stores application data that will not fit into the primary data file – generally added to additional disk drives.

11 Prentice Hall © 200411 Database Files Contd.

12 Prentice Hall © 200412 Disk Storage Database objects are stored using two units of storage – page and extent.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.Database files are divided into pages while several pages are grouped into extents. Pages are 8Kb in size.Pages are 8Kb in size. A data row cannot span pages in SQL Server – the maximum row size is 8,060 bytes.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.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.Extents are contiguous pages allocated with 8 pages/extent.

13 Prentice Hall © 200413 Creating an SQL Server Database The CREATE DATABASE statement can be used with SQL Query Analyzer to create a 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.Enterprise Manager is easier to use – right-click the database node or use the Action menu - New Database option.

14 Prentice Hall © 200414 Database Properties – General Tab

15 Prentice Hall © 200415 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.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.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.The data file has an initial size of 1Mb and is set to automatically grow in 10% increments.

16 Prentice Hall © 200416 Database Properties – Data Files Tab Contd.

17 Prentice Hall © 200417 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.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.Here the transaction log is named TestDatabase_Log on drive C: in the folder named C:\DataLogs.

18 Prentice Hall © 200418 Database Properties – Transaction Log Tab Contd.

19 Prentice Hall © 200419 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.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.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.Use Enterprise Manager to create a filegroup by a right-click of the database in the Tree panel and selection of the Properties menu.

20 Prentice Hall © 200420 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.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.

21 Prentice Hall © 200421 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.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', FILENAME = 'C:\Data\TestDatabase_Data.Mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 25% ), SIZE = 10, MAXSIZE = 50, FILEGROWTH = 25% ), FILEGROUP TestDatabaseGroup1 ( NAME = TestDatabaseSecondary1_Data, FILENAME = 'D:\Data\TestDatabaseSecondary1_Data.Ndf', FILENAME = 'D:\Data\TestDatabaseSecondary1_Data.Ndf', SIZE = 20, MAXSIZE = 50, FILEGROWTH = 5% ), SIZE = 20, MAXSIZE = 50, FILEGROWTH = 5% ),

22 Prentice Hall © 200422 Create Database Options to Create Filegroups Contd. FILEGROUP TestDatabaseGroup1 ( NAME = TestDatabaseSecondary1_Data, FILENAME = 'D:\Data\TestDatabaseSecondary1_Data.Ndf', FILENAME = 'D:\Data\TestDatabaseSecondary1_Data.Ndf', SIZE = 20, MAXSIZE = 50, FILEGROWTH = 5% ), SIZE = 20, MAXSIZE = 50, FILEGROWTH = 5% ), ( NAME = TestDatabaseSecondary2_Data, FILENAME = 'E:\Data\TestDatabaseSecondary2_Data.Ndf', FILENAME = 'E:\Data\TestDatabaseSecondary2_Data.Ndf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5% ) SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5% ) LOG ON ( NAME = 'TestDatabase_Log', FILENAME = 'G:\Datalogs\TestDatabase_Log.Ldf', FILENAME = 'G:\Datalogs\TestDatabase_Log.Ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB ); SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB );

23 Prentice Hall © 200423 SQL Server System Catalog The SQL Server system catalog consists of system tables in the Master database.The SQL Server system catalog consists of system tables in the Master database. System tables stored in individual databases are the database catalog.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).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.Only SQL Server should modify the system catalog.

24 Prentice Hall © 200424 SQL Server and Database Accounts Both SQL Query Analyzer and Enterprise Manager can create SQL Server login 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.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’;

25 Prentice Hall © 200425 Using Enterprise Manager to Create Login Accounts Select Tools menu, Wizards option and expand the Database tree.Select Tools menu, Wizards option and expand the Database tree. Select the Create Login Wizard option shown here.Select the Create Login Wizard option shown here.

26 Prentice Hall © 200426 Creating Login Accounts – Contd.

27 Prentice Hall © 200427 Creating Login Accounts – Contd.

28 Prentice Hall © 200428 Creating Login Accounts – Contd.

29 Prentice Hall © 200429 Default Database User Accounts Users needing access to specific application databases must have a valid database user account for that database.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.Each database has two default accounts: dbo and guest. The dbo account owns a database and the account cannot be dropped.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.The guest account is used by users who have no specific database user account.

30 Prentice Hall © 200430 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.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.This example associates a database user account named robertsmith with a Windows user account named rsmith. EXEC sp_grantdbaccess ‘rsmith’, ‘robertsmith’

31 Prentice Hall © 200431 Creating Database User Accounts Contd. Enterprise Manager can be used as shown here to create database user accounts.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.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.

32 Prentice Hall © 200432 Revoking Database User Accounts Through Enterprise Manager

33 Prentice Hall © 200433 Roles Roles make it easier for a DBA to manage the allocation of permissions.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.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.Each accountant hired will be authorized the permissions contained in the role named Accountant. This also applies to other jobs such as Clerk.This also applies to other jobs such as Clerk.

34 Prentice Hall © 200434 Roles Contd.

35 Prentice Hall © 200435 Fixed Server Roles Fixed server roles exist at the server level external to databases.Fixed server roles exist at the server level external to databases. Several fixed server roles exist. These include: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.

36 Prentice Hall © 200436 Allocating Fixed Server Roles – Enterprise Manager Expand the security folder and select the Server Roles option. Right-click the role as shown.Expand the security folder and select the Server Roles option. Right-click the role as shown.

37 Prentice Hall © 200437 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.Click the Add button to display the Add Members window as shown and add the members desired and click OK.

38 Prentice Hall © 200438 Fixed Database Roles These roles exist for each database and are grouped according to purpose. They include: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.

39 Prentice Hall © 200439 Application Roles These roles are used to allocate specific permissions for specific applications such as payroll or inventory management.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 are allocated to login sessions. Application roles require a password.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.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’

40 Prentice Hall © 200440 User-Defined Database Roles This is the more traditional use of roles – to allocate permissions to groups of users as was described earlier.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.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 */ /* Example Granting Role */ EXEC sp_addrole ‘clerk’, ‘bbordoloi’ EXEC sp_addrole ‘clerk’, ‘bbordoloi’ EXEC sp_addrolemember ‘clerk’, ‘dbock’ EXEC sp_addrolemember ‘clerk’, ‘dbock’

41 Prentice Hall © 200441 Permissions Permissions authorize database users to perform various operations such as CREATE DATABASE and SELECT.Permissions authorize database users to perform various operations such as CREATE DATABASE and SELECT. Permissions are divided into two categories: statement and object.Permissions are divided into two categories: statement and object.

42 Prentice Hall © 200442 Granting Statement Permissions Use the GRANT statement to grant permissions. Statement permissions include: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

43 Prentice Hall © 200443 Granting Statement Permissions – Contd. Grant all permissions to dbock.Grant all permissions to dbock. GRANT ALL TO dbock; GRANT ALL TO dbock; Grant two permissions to tthumb and bbordoloiGrant two permissions to tthumb and bbordoloi GRANT CREATE TABLE, CREATE VIEW TO tthumb, bbordol; tthumb, bbordol; Grant permissions to a role.Grant permissions to a role. GRANT CREATE PROCEDURE, CREATE FUNCTION TO clerk; TO clerk;

44 Prentice Hall © 200444 Granting Object Permissions Contd. Object permissions apply to a specific database object such as a table.Object permissions apply to a specific database object such as a table. Permissions include SELECT, UPDATE, INSERT, DELETE, and other object manipulations.Permissions include SELECT, UPDATE, INSERT, DELETE, and other object manipulations.

45 Prentice Hall © 200445 Granting Object Permissions Contd. General form of the GRANT statement: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}] [WITH GRANT OPTION] [AS {group_name | role_name}] The object is specified with the ON clause.The object is specified with the ON clause. The TO clause specifies who receives the permission.The TO clause specifies who receives the permission. The WITH GRANT OPTION enables the grantee to grant the permission to others.The WITH GRANT OPTION enables the grantee to grant the permission to others.

46 Prentice Hall © 200446 Granting Object Permissions – Contd. Grant SELECT on the dependent table.Grant SELECT on the dependent table. GRANT SELECT ON dependent TO bbordoloi; GRANT SELECT ON dependent TO bbordoloi; Grant SELECT and DELETE on the dependent table.Grant SELECT and DELETE on the dependent table. GRANT SELECT, DELETE ON dependent TO dbock; GRANT SELECT, DELETE ON dependent TO dbock; Grant UPDATE on specific table columns.Grant UPDATE on specific table columns. GRANT UPDATE ON dependent( dep_name, dep_gender) GRANT UPDATE ON dependent( dep_name, dep_gender) TO bbordoloi; TO bbordoloi; Grant ALL permissions to everyone (PUBLIC).Grant ALL permissions to everyone (PUBLIC). GRANT ALL ON dependent TO PUBLIC; GRANT ALL ON dependent TO PUBLIC;

47 Prentice Hall © 200447 Granting Object Permissions – Enterprise Manager

48 Prentice Hall © 200448 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.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; TO dbock;

49 Prentice Hall © 200449 Revoking Permissions You can revoke both statement and object permissions. Permissions that are revoked can later be allocated again.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.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; dependent FROM dbock CASCADE;

50 Prentice Hall © 200450 System Procedures System procedures such as the sp_help procedure can be used to display information about database objects.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...

51 Prentice Hall © 200451 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.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

52 Prentice Hall © 200452 Summary A SQL Server installation is managed through the Enterprise Manager.A SQL Server installation is managed through the Enterprise Manager. A SQL Server database includes physical and logical objects such as files and filegroups.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.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 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.You also learned to allocate, deny, and revoke system and object permissions to/from accounts and roles.


Download ppt "Prentice Hall © 20041 Chapter 11: SQL Server Database Administration SQL for SQL Server Bijoy Bordoloi and Douglas Bock."

Similar presentations


Ads by Google