Microsoft SQL Server 2000 Administration

937 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
937
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
29
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Microsoft SQL Server 2000 Administration

  1. 1. Check out these great features at www.cramsession.com > Discussion Boards http://boards.cramsession.com Your Trusted Study Resource > Info Center for http://infocenter.cramsession.com Technical Certifications > SkillDrill http://www.skilldrill.com Written by experts. The most popular > Newsletters study guides http://newsletters.cramsession.com/default.asp on the web. In Versatile > CramChallenge Questions http://newsletters.cramsession.com/signup/default.asp#cramchallenge PDF file format > Discounts & Freebies http://newsletters.cramsession.com/signup/ProdInfo.asp Microsoft SQL Server 2000 Administration Version 3.0.0 Notice: While every precaution has been taken in the preparation of this material, neither the author nor Cramsession.com assumes any liability in the event of loss or damage directly or indirectly caused by any inaccuracies or incompleteness of the material contained in this document. The information in this document is provided and distributed "as-is", without any expressed or implied warranty. Your use of the information in this document is solely at your own risk, and Cramsession.com cannot be held liable for any damages incurred through the use of this material. The use of product names in this work is for information purposes only, and does not constitute an endorsement by, or affiliation with Cramsession.com. Product names used in this work may be registered trademarks of their manufacturers. This document is protected under US and international copyright laws and is intended for individual, personal use only. For more details, visit our legal page.
  2. 2. Microsoft SQL Server 2000 Administration Microsoft SQL Server 2000 Administration Version 3.0.0 Abstract: This study guide will help you prepare for Microsoft exam 70-228, Installing, Configuring, and Administering Microsoft SQL Server 2000 Enterprise Edition. Exam topics include: installing and configuring SQL Server 2000; creating SQL Server 2000 databases; managing, monitoring, and troubleshooting SQL Server 2000 databases; extracting and transforming data with SQL Server 2000; managing and monitoring SQL Server 2000 security; and managing, monitoring and troubleshooting SQL Server 2000. Find even more help here: © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 1
  3. 3. Microsoft SQL Server 2000 Administration Contents: Installing and Configuring Microsoft SQL Server 2000.......................................... 4 Hardware ................................................................................................... 4 Software .................................................................................................... 5 Upgrading .................................................................................................. 5 SQL Server 6.5 ........................................................................................ 5 SQL Server 7.0 ........................................................................................ 5 Verifying and Troubleshooting Installation .................................................... 6 Configuration.............................................................................................. 6 Operator ................................................................................................. 6 SQLAgentMail .......................................................................................... 6 SQL Mail Configuration ................................................................................. 7 Linked Servers ............................................................................................ 7 Security for Linked Servers ........................................................................ 8 Creating SQL Server 2000 Databases................................................................ 9 Predicting and Managing Growth ................................................................... 9 Database Files.......................................................................................... 9 Auto Shrink ............................................................................................. 9 Manually Shrinking the Database ...............................................................10 Creating a Database ...................................................................................11 Modifying a SQL Server 2000 Database .........................................................12 Views.....................................................................................................13 Stored Procedures ...................................................................................13 Managing, Monitoring, and Troubleshooting SQL Server 2000 Databases...............14 Optimizing Performance of SQL Server 2000 Databases ...................................14 Indexing ................................................................................................14 Locking ..................................................................................................14 Recompiling ............................................................................................14 Optimize Data Storage .............................................................................15 File Groups .............................................................................................15 Perform Disaster Recovery Operations...........................................................16 Backup and Restoration of SQL Server Databases ........................................16 Restoring Data ........................................................................................16 Retaining Database Integrity........................................................................16 DBCC Transact-SQL Statements ................................................................17 Troubleshooting SQL Server 2000.................................................................18 Locking ..................................................................................................18 Blocking .................................................................................................18 Monitoring Tools ......................................................................................19 Extracting and Transforming Data with SQL Server 2000 ....................................19 IIS Virtual Directories and XML.....................................................................19 System Requirements ..............................................................................19 Importing and Exporting Data ......................................................................20 © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 2
  4. 4. Microsoft SQL Server 2000 Administration Data Transformation Services....................................................................20 Develop and Manage DTS Packages ...........................................................20 Bulk Insert Task ......................................................................................21 Bulk Copy Program ..................................................................................21 Data Type Conversion .................................................................................22 Implicit Conversion ..................................................................................22 Explicit Conversion ..................................................................................23 Replication Services – Configuration, Troubleshooting, and Maintenance ............23 Snapshot Replication................................................................................23 Transactional Replication ..........................................................................24 Merge Replication ....................................................................................24 Managing and Monitoring SQL Server 2000 Security...........................................25 Create and Manage Log Ons ........................................................................25 Windows Authentication ...........................................................................25 SQL Server Logins ...................................................................................25 Create and Manage Database Users ..............................................................26 Database Access .....................................................................................26 Create and Manage Security Roles ................................................................27 Fixed Server Role ....................................................................................27 Fixed Database Role ................................................................................27 User-Defined Role....................................................................................27 Application Role.......................................................................................27 Database Permissions .................................................................................28 Statement Permissions .............................................................................28 Object Permissions ..................................................................................28 Predefined Permissions.............................................................................28 SQL Server 2000 Management, Monitoring and Troubleshooting ..........................29 Create, Manage, and Troubleshoot SQL Server Agent Jobs ...............................29 Configure Alerts and Operators by Using SQL Server Agents.............................29 Alerts.....................................................................................................29 Operators ...............................................................................................30 Error Codes ............................................................................................30 Paging Alert ............................................................................................30 Configuring Jobs for SQL Agent .................................................................31 Optimizing Hardware Resources and Usage ....................................................32 Memory Usage ........................................................................................32 CPU Processor Utilization ..........................................................................32 Disk I/O Performance...............................................................................32 User Connections.....................................................................................32 Blocking Locks ........................................................................................32 Monitoring Hardware Resources and Resolving System Bottlenecks.................33 Optimizing and Troubleshooting SQL Server System Activity.............................33 Monitoring SQL Server Activity by Using Traces............................................33 Monitoring SQL Server Activity by Using System Monitor ...............................34 © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 3
  5. 5. Microsoft SQL Server 2000 Administration Installing and Configuring Microsoft SQL Server 2000 Hardware The first thing to consider when installing SQL Server is your hardware. The processor in your machine must be 166 MHz or better. Obviously, the more powerful the processor, the better off you’ll be. SQL Server 2000 can make use of a maximum of 32 processors. Next, you want to look at RAM. This is going to depend on which OS you are installing SQL Server 2000. If you are installing on any version of Windows 2000 Server, then you will need to have at least a minimum of 256 MB of RAM. If you are installing on Windows NT4 Servers, then you will only need the recommended minimum of 64 MB of RAM. However, SQL Server 2000 can take advantage of up to 64 GB of RAM, utilizing the extra memory to avoid writing to disk. After RAM, you should check your hard disk space. For a typical installation of SQL Server 2000, you will need 250 MB of free space. For a full install, you will need 270 MB of RAM. This is broken up as follows: 100 MB of space for the client tools, 50 – 130 MB of free space for the Analysis Services, and 80 MB of free space for the English Query. Note: If you are using a Hard Disk with a write-caching controller, make sure it is specially designed for databases. Other write-caching controllers can cause problems. If you have the required hardware for Windows 2000, you will be able to install SQL Server 2000. You can verify that your hardware is compatible with Windows 2000 by checking with Microsoft’s Windows 2000 Hardware Compatibility List (HCL). © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 4
  6. 6. Microsoft SQL Server 2000 Administration Software The Operating Systems allowed are based upon which version of SQL Server 2000 you are installing. The following table from, Microsoft’s “Administering an SQL Server 2000 Database” textbook, lists the various options open to you. SQL Server Windows Windows Windows 98 Windows 2000 2000 & 2000 & Windows CE Edition Windows NT Professional Millennium Server & (ME) Windows NT Workstation Enterprise Yes No No No Enterprise Yes No No No Evaluation Standard Yes No No No Developer Yes Yes No No Personal Yes Yes Yes No Windows CE No No No Yes Upgrading When you are upgrading a previous version of SQL Server such as 6.5, or 7.0 there are certain steps to take. If you are upgrading from SQL Server 6.0, then you need to first upgrade to SQL Server 6.5 or SQL Server 7.0. Then you can upgrade to SQL Server 2000. SQL Server 6.5 If you are running SQL Server 6.5, then you can install SQL Server 2000 using either the default location, or a customized location, both of which install a new occurrence of SQL Server. You can then use Version Switching to switch back and forth from one to the other. Note: If you wish to have SQL Server version 6.5 and version 2000 installed together, then you need to install SQL Server Service Pack 5 to the 6.5 install prior to installing SQL Server 2000. SQL Server 7.0 SQL Server 7.0 can be upgraded to SQL Server 2000 simply by installing a default installation. This will upgrade the system. If you use a customized location, then you can have two separate installations of SQL Server. This article (KB: Q260414) will give you more information regarding Multiple Instances of SQL Server on one © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 5
  7. 7. Microsoft SQL Server 2000 Administration machine. Also, check article (KB: Q261334) for answers regarding upgrading existing versions of SQL Server. For more information on installing SQL Server, check out this article (KB: Q257716). Verifying and Troubleshooting Installation The installation can be verified by starting up the SQL Server Query Analyzer and entering “SELECT @@VERSION”. This command will return the current SQL Server product version information. You can also verify the file folder located in “C:Program FilesMicrosoft SQL Server” and all subfolders beneath this. If the installation fails, troubleshooting should begin based on the message displayed on the screen during setup. You can also review the error log file located at “C:WinntSqlstp.log”. Configuration Once SQL Server 2000 is installed, you can configure the SQL Server Agent Service to help provide you with automation of jobs and maintenance procedures and also to alert you to errors and problems with the system. Operator First thing you need to do is create an Operator. Start the SQL Server Enterprise Manager. Expand the Microsoft SQL Servers and the SQL Servers Group selections. Select and expand the SQL Server you wish to set up the operator on. Then expand the Management folder and the SQL Server Agent. Highlight Operators. Right-click on Operators and select New Operator from the menu. Enter the operator’s name as well as any method you wish to use for Notification, such as an email address, net send address, or pager email. If you use the pager email option, enter the available pager email days and times. SQLAgentMail Then you need to configure SQL Mail and SQLAgentMail. You need to have a valid MAPI mail service configured on the system, such as Microsoft Outlook. For SQLAgentMail the first thing you need to do is make sure the SQL Server Agent is running. Right-click on SQL Server Agent and select properties. You will get a window titled “SQL Server Agent – (server name)”. Make sure you are on the General tab, and in the Mail Profile section, select MS Exchange Settings from the drop down list. Click OK and then stop and restart the SQL Server Agent Service. When it is fully restarted, you can verify that this was successful by right- clicking on the SQL Server Agent and selecting Display Error Log. Within this log you can verify that your mail session started when you restarted the agent. Now © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 6
  8. 8. Microsoft SQL Server 2000 Administration when you configure jobs and alerts, you can set up notification for an operator (such as the one you configured before) via email. SQL Mail Configuration SQL Mail allows you to query your database through email and have results returned via email. It is required that you log on to SQL Server with a domain user account with a valid email profile. SQL Mail will take a single query from an incoming email to the domain user account used by SQL Server and process the request. The returned result set will be sent back to the person who sent the query via email. To configure SQL Mail, expand the Support Services option on the tree menu. Right-click on SQL Mail and select Properties from the menu. Select MS Exchange Settings from the Profile name drop down list. Also check off the box for “Autostart SQL Mail when SQL Server starts”. This will ensure that it is always running. For more information on SQL Mail configuration, check out this Microsoft article (KB: Q263556). Linked Servers Configuring Linked Servers allows SQL Server to access different OLE DB data stored on other servers. This could be other SQL Server Databases, or it could be files such as spreadsheets and text files. One method you can use to add a linked server is to execute the stored procedure sp_addlinkedserver. You can also add a Linked Server through SQL Server Enterprise Manager. Expand the Microsoft SQL Servers and the SQL Servers Group selections. Expand the Security folder underneath the local SQL Server. Highlight and right-click on Linked Servers. Select Properties from the menu selections. In the window “Linked Server Properties – New Linked Server” enter a name for the server you wish to link to in the Linked Server field. If it is a file, then simply give it a valid name to explain what it is you are linking to. If it is an SQL Server, then use the name of the server. Next, select either SQL Server or Other Data Source depending on which you are using. If you are linking to a file, select the proper Provider Name from the drop down list. Fill in the Product Name, Data Source, and the Provider String. Next step is to click on the Security tab. Select the login security you wish to use for the linked server. Your options are: © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 7
  9. 9. Microsoft SQL Server 2000 Administration • No security context will be used – meaning that no restrictions will be placed on logins. • They will be impersonated. • They will be mapped to – select a remote user account and password. This will allow all non-specified logins to use the remote user account. Apply proper security permissions to this login. • They are not allowed to access – this would set maximum security for your linked server. If they are not a specified user, then they will not be allowed access to the linked server. In the login section of the window, you will select from the SQL Server user accounts which accounts will be given access to your linked server. These are local logins for SQL Server, not domain accounts. You can modify permissions to these logins by going to the Logins selection under the Security folder underneath the server on the SQL Server tree. You can configure an OLE DB provider such as a Linked Server for Distributed Queries, using several options. One such option is “use remote collation”. This option can be set to True and False. If True, then the collation information from the Linked Server’s character columns will be used. The information will be taken directly from the OLE DB provider interface, but only if the Linked Server is an instance of SQL Server. The collation information from the Collation Name option will be used if the Linked Server is not an instance of SQL Server. If the option is set to False, the character information from the specified linked server will be used. Security for Linked Servers When a linked server connection is made between two servers, one acts as the sending server and the other as the receiving server. A login name and password must be provided to the receiving server by the sending server in order for the connection to be made. To make this connection possible there should be a linked server login mapping. To create a linked server login map, several methods may be used. One such method is employing the stored procedure sp_addlinkedsrvlogin through Transact-SQL. You can also use the stored procedure sp_droplinkedsrvlogin to delete the mapping. The way this login mapping works is that a remote login and password for the linked server are mapped to a local login on the local server. When a connection is attempted between the local server and the linked server in order to execute a query or procedure, the local login is checked against the linked server login map. If there is a mapping from the local server with the local login to the © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 8
  10. 10. Microsoft SQL Server 2000 Administration linked server and a remote login and password, then the connection will be made. If there is not a corresponding remote login and password for the local login on the linked server, the connection will fail. Another method of creating a linked server login map is through the Enterprise Manager. The first step is to expand a server group, and then a server. Next you would expand the security folder, and then the linked servers option. Select the linked server that you will be adding the logins to. Right-click and select the properties option. Click on the Security tab. Select the logins to be added. In the given fields, enter the remote login and remote password to be linked to. As an option, you can select the Impersonate check box, which will allow the local login to login to the linked server using its own security credentials. Creating SQL Server 2000 Databases Predicting and Managing Growth The first thing to consider when creating a database is growth. Will this be a heavily used database, or will it be used infrequently? You can set a database to grow in increments by megabytes, or percentage. Also, you can restrict the size of the database to a certain size in megabytes, or you can allow unrestricted growth of the database. Disk space and usage considerations will determine which of these options you will select. This will be set individually for each of the three files making up the database. The three typical files have the extensions .mdf, .ndf, and .ldf. Database Files The .mdf file is the primary data file or filegroup. Filegroups are named collections of data files. The primary file or filegroup will contain the data and system tables, unless the data is specifically assigned to user-defined filegroups. The .ndf file is the history file, or secondary data file or files. Secondary files may be on multiple disks to distribute the data. Also included is the .ldf file, which is a log file containing all transactions. All databases have a transaction log, which is typically about 10 to 15 percent of all data files. Auto Shrink An option for space consideration is Auto Shrink. This will compress the database whenever space opens up within from data deletion, by executing the stored procedure sp_dboption. The database cannot ever be shrunk to a size smaller than it was upon creation. So if you had created the database size to be 15MB initially, even with all data deleted, it will never be smaller than 15MB. Also the amount of free space removed to compress the database cannot be configured to a specific © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 9
  11. 11. Microsoft SQL Server 2000 Administration amount. The system determines what is available free space within the database, and removes it, thereby compressing the database and shrinking the size. Manually Shrinking the Database As an alternative, you can leave the Auto Shrink option off, and shrink the database manually when you need to. You can do this through Transact-SQL by using the command “DBCC Shrinkdatabase”. The syntax of the command is shown in this example. DBCC SHRINKDATABASE ( database_name [, target_percent] [, {NOTRUNCATE | TRUNCATEONLY}] ) This can also be done through the SQL Server Enterprise Manager. You would simply expand the tree down to the database level. Right-click on the database you wish to shrink, and select “All Tasks” from the menu. Then select “Shrink Database” from the submenu list. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 10
  12. 12. Microsoft SQL Server 2000 Administration Creating a Database You can create the database either by using the Wizard Tools or by using the SQL Server Query Analyzer. You would use the statement “Create Database”. With this statement you must also define all parameters of the database, such as the associated files .mdf, .ndf, and .ldf. Here is an example of the command. USE master GO CREATE DATABASE Example ON ( NAME = Example_dat, FILENAME = 'c:mssql7dataExampledat.mdf', SIZE = 10, MAXSIZE = 50, FILEGROWTH = 5 ) LOG ON ( NAME = 'Example_log', FILENAME = 'c:mssql7dataExamplelog.ldf', SIZE = 5MB, MAXSIZE = 25MB, FILEGROWTH = 5MB ) GO © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 11
  13. 13. Microsoft SQL Server 2000 Administration Modifying a SQL Server 2000 Database Once you have your database created, or if you are using an existing database, you might find the need to modify or add files. You can do this with the “Alter Database” command in SQL Server Query Analyzer. Here is an example of how to add a file using the “Alter Database” command. USE master GO CREATE DATABASE Example1 ON ( NAME = Example1dat1, FILENAME = 'c:mssql7dataE1dat1.ndf', SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB ) GO ALTER DATABASE Example1 ADD FILE ( NAME = Example1dat2, FILENAME = 'c:mssql7dataE1dat2.ndf', SIZE = 5MB, MAXSIZE = 100MB, FILEGROWTH = 5MB ) GO This command can also remove files from the database. You can modify properties of the files, such as size, using this command. This flexibility allows you to keep your database functioning optimally, as needs change. You can also modify file properties through the SQL Server Enterprise Manager simply by expanding the tree until you find the database you wish to modify. Highlight the database and right-click on it. Select Properties from the menu and © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 12
  14. 14. Microsoft SQL Server 2000 Administration then you can select either the data file, history file, or log file and set the size and growth properties accordingly. You can also modify the file path of the files either within the SQL Server Enterprise Manager or by using the “Alter Database” command. More information on optimizing SQL Server can be found in this article (KB: Q110352). Depending on your needs you may also create objects such as database Views and Stored Procedures. Views A View is a selected amount of the database available to a certain user. This would be based on security privileges assigned to select users. You could allow certain individuals to access only certain columns of a table. This would be useful if someone required access to certain information contained in a table that also had information that was only available to certain other individuals within the organization. You would then give the individual access to the columns they need and only those columns. For further reference on views, go to this page, Using Views as Security Mechanisms. Stored Procedures A Stored Procedure is a set of Transact SQL commands available to be executed at anytime. This is also known as a single execution plan. Users do not have to run each of the Transact SQL commands within the stored procedure. They simply need to use the EXECUTE or CALL statements with the stored procedure name, which usually starts with sp_. This can make using the database easier as well as keeping users from accessing the details of the tables. Common tasks can be set up in a stored procedure and then executed when needed, such as in a maintenance plan. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 13
  15. 15. Microsoft SQL Server 2000 Administration Managing, Monitoring, and Troubleshooting SQL Server 2000 Databases Optimizing Performance of SQL Server 2000 Databases The primary objective with optimizing performance is to decrease the time spent on queries against the database, and to maximize data flow. One way to do this is to minimize network traffic. Another way is to minimize CPU usage. Also, minimizing disk I/O will help. While designing your database, you will want to consider the logical design and the physical design. Logical Design refers to the use of database constraints and tables and following business and data considerations regardless of physical storage locations. A good Logical Design begins with normalization of the data. This means avoiding redundancies in the data by avoiding updating the same data in multiple tables. This can be done through linked tables using relational joins. This will improve efficiency and reduce inconsistent data errors. Indexing Using Primary and Foreign keys to uniquely index your data will help speed up query processing also, by guaranteeing unique rows. More on keys and indexing can be found on this page, Database Designer Considerations for SQL Server Databases. Locking You can also optimize your database by using Locking whether it is SQL Server’s default locking procedures, or by customizing applications to enforce locking. Locking is a method in which data being modified by one user is unable to be read or modified by another user. Recompiling Another method of optimizing performance of your queries is by Recompiling. This ensures that if a table’s data has changed, or if a new index has been added that the query could take advantage of, that the query will run as quickly as possible. Stored procedures and queries will recompile automatically when they are run the first time the data has changed, except in the situation of a new index being added. In this case, you would need to either recompile using the stored procedure sp_recompile or by using the “WITH RECOMPILE” option in your Transact SQL code. The “WITH RECOMPILE” option will recompile your code every time it is executed, prior to execution. This option works best if the data changes often. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 14
  16. 16. Microsoft SQL Server 2000 Administration Optimize Data Storage Another consideration for optimization is Data Types. For example, a fixed length char field allowing null values will take up more space than a varchar field allowing null values. Using char types in turn takes up more disk space and I/O processing power. So recommended practice would be to use varchar data types over char data types for a field that often has varying lengths and/or null values. Further reading on data types can be found on this page, SQL Data Types. Reference on Transact SQL and data types can be found on this page, Data Types. File Groups Physical Design is another way to optimize your database performance. This would include hardware considerations such as a RAID setup. This also includes data placement, using filegroups. A hardware RAID solution is good because the firmware takes care of I/O processing efficiently. However, it is expensive and there is a software alternative. Operating system-based RAID setups are less expensive, and also increase I/O processing performance, although this method does consume processor cycles. For SQL Server, typical RAID implementations are usually RAID 0, 1, and 5. RAID 0 (Data Striping), tends to give SQL Server the highest performance, but is weak in data recovery, since if one disk crashes, the whole data stripe set is inaccessible. RAID 1 offers better recoverability and high performance I/O by storing the transaction log on a mirrored disk and the database on a RAID 0. Of course, high level of data recoverability assumes you perform regular database and transaction log backups. For further reading on RAID levels and SQL Server, go to this page, RAID Levels and SQL Server. Using filegroups allows you to split large tables into smaller, related tables, thus improving processing due to smaller amounts of data to scan. You can place each table on a separate disk drive to spread processing out over multiple disks. This is also good for when your database reaches a critical size, such as the maximum file size allowed by Windows. With filegroups you can still allow your database to grow. For information on placing tables on filegroups, go to this page, Placing Tables on Filegroups. Also, further reading on filegroups can be found on these pages: Using Files and Filegroups and Physical Database Files and Filegroups. An overview of optimization practices can be found on this page, Optimizing Database Performance Overview. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 15
  17. 17. Microsoft SQL Server 2000 Administration Perform Disaster Recovery Operations Backup and Restoration of SQL Server Databases Backing up your database is one of the most important parts of Administering SQL Server. Backups help you recover your data in the event of a disaster. This could include hard disk failure, other hardware failure, and corruption of data or something more serious such as a building fire or collapse. Having a good, current backup also enables you to move or copy your database to a backup server, or secondary server quickly and easily. Restoring Data A backup of your database is an exact replica of the data contained at the time of the backup’s completion. Backing up the database should always be accompanied by backing up the transaction log. The transaction log keeps track of the transactions up to the point of the database backup’s start. When restoring a database, restoring the transaction log at the same time enables you to keep your database data consistent. The transaction log will roll back any transactions that were not completed by the time the backup of the database completed. The transaction log will also roll forward any transaction that was finished by the time the database backup completed. This ensures that you do not have partially manipulated data within your database. This is accomplished by restoring the database first, then reading through the transaction log forwards, restoring all completed transactions. This restores the database to the same exact state it was in when the backup was created. The more use a database gets, the more often it should be backed up. Backups can be automated through use of a Maintenance plan. This can be scheduled as a SQL Server Agent job to run at certain times regularly. Ideally, you can schedule this to run during a low usage point to backup current data. Items to consider would be storage location and frequency of backups. Retaining Database Integrity This can be done through usage of Maintenance plans running stored procedures to accomplish such tasks as shrinking the database and indexing the database. Database integrity can also be kept by using the Database Consistency Checker or DBCC Transact-SQL statements. DBCC statements will determine the physical consistency of the database, as well as the logical consistency. Detected problems may or may not be repaired through DBCC statements. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 16
  18. 18. Microsoft SQL Server 2000 Administration DBCC Transact-SQL Statements There are four groups of DBCC Transact-SQL statements. These are: • Maintenance Statements • Miscellaneous Statements • Status Statements • Validation Statements For details on the DBCC Transact SQL statements, go to this page, DBCC. On this page, Rebuilding an Index, you can find information on rebuilding an index. Maintenance Statements can perform maintenance tasks. These can be performed on the database directly, such as repairing the database or shrinking the database. They can also be used to perform such functions as re-indexing the database. Functions performed on filegroups would include shrinking the file and updating usage. An example of shrinking the Transaction log file can be found on this page, Shrinking the Transaction Log. Miscellaneous Statements can perform functions such as releasing a .dll file from active memory. When a stored procedure executes, any .dll file called will be kept in active memory until either manually released or until the server is shut down. Other miscellaneous functions performed would include row-level locking. This would enable select rows to be locked and unavailable for usage. Row-level locking is typically used in regards to SQL Server 6.5 scripts and databases. Included in miscellaneous functions is turning on and off Trace Flags. Trace Flags are usually used for debugging stored procedures or troubleshooting performance issues. Status Statements give status information regarding such things as all set options for a client connection. They can also return such information as the last statement sent to SQL Server. Information can also be provided for space used by all transactions logs through Status Statements. Validation Statements can be used to provide validation information for the entire database, select tables or indexes, filegroups, catalogs, or database page allocations. One thing to remember while running the Validation Statement “DBCC CHECKDB” is that it is disk intensive. It also uses tempdb to handle sorting, so it is recommended that you put tempdb onto a separate disk to speed up the process. Also “DBCC CHECKDB” blocks transaction log truncation, so the transaction log will grow during the command’s execution. “DB CHECKDB” is also CPU intensive, and should be run during a time when the load on the server is light. For more © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 17
  19. 19. Microsoft SQL Server 2000 Administration information on DBCC Validation Statements, go to this page, Data Integrity Validation. There is a SQL Maintenance utility that you are able to use to run select maintenance plans from the command line. On this web page, sqlmaint Utility, you will find more information and syntax for the command. Troubleshooting SQL Server 2000 Locking One type of issue you may run into with SQL Server is locking. There are two different types of locking that may be occurring. One of these types is Deadlocking. The other is Blocking. Deadlocking is found on multi-user systems. This occurs when two separate users are each locking one object. These same users then try to lock onto each other’s object. This causes Deadlocking while they each wait for the other’s lock to end. When SQL Server detects a deadlock it will choose one user to be a “deadlock victim” and causes that application to return an error. The transaction that the deadlock victim was trying to execute is rolled back. If deadlocks occur often and cause serious system degradation, then you should execute a Trace Flag. Trace flag 1204 will provide more in-depth error checking. This will cause all messages to be shown on the console SQL Server started on as well as having all messages written to the error log. Executing the following at the command prompt, “C:Program Filesmssqlbinnsqlservr –T1204”, will start SQL Server with the Trace Flag enabled. Blocking Blocking occurs when a single connection has a lock on an object. Then a second connection attempts to put a lock on the same object. This causes the second connection to either wait or to block out the first connection. This can occur whether the second connection is from the same application on the same system or a separate application on a separate system. In order to troubleshoot deadlocking and blocking errors on a system, a system administrator should check the sysprocesses table in the Master database. Unique SPID’s (System Process ID) will represent each connection to the server. The relevant columns to check would be waittime, waittype, lastwaittype, and waitresource. This can be done through the Enterprise Manager, by expanding the tree down to the Master database tables and right clicking on the sysprocesses table and selecting “Return all rows”. This can also be accomplished by entering the © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 18
  20. 20. Microsoft SQL Server 2000 Administration Query Analyzer and entering the command “Select * from sysprocesses”. This can be further narrowed down to the relevant columns simply by entering the command “Select spid, waittime, waittype, lastwaittype, waitresource from sysprocesses”. Monitoring Tools Information on Monitoring Tools available in SQL and how to implement them can be found on this Microsoft web page, Choosing a Monitoring Tool. Extracting and Transforming Data with SQL Server 2000 IIS Virtual Directories and XML SQL Server 2000 is the first version of SQL Server to support XML functionality. This enables you to access SQL Server 2000 through HTTP and to write and retrieve XML data. SQL Server becomes accessible through HTTP via an IIS Virtual Directory Root. System Requirements System requirements for the IIS Virtual Directory include having Microsoft Internet Information System 4.0 or better installed. Requirements also include having Microsoft Management Console 1.2 installed (from either the Windows NT 4.0 option pack or SQL Server 2000 disk). You can manipulate the IIS Virtual Directory manually through a graphical utility or programmatically through the object model. When setting up a new virtual directory on the IIS server, you need to ensure that the name of the IIS server and the name of the virtual directory are included in the URL. Necessary information, such as logins, access permissions and passwords, must be set up also in order to create a connection to the database. In order to access database objects directly, the URL needs to incorporate a virtual dbobject. XML templates can also be executed through the URL. Templates are SQL statements in a valid XML document. When the XML template is executed at the URL level, the SQL statements are executed. For security reasons, you would never execute SQL statements at the URL level. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 19
  21. 21. Microsoft SQL Server 2000 Administration Importing and Exporting Data Data Transformation Services Data Transformation Services (DTS) is a utility within SQL Server that allows you to import and export data. These imports and exports can be done to and from text files, spreadsheets, and OLE DB files, such as Microsoft Access Databases. Several steps can be built into the DTS package for execution. These steps can be conditional based upon the success or failure of a previous step, or can be executed singularly. Several steps without conditions can be run simultaneously. Here is an overview of Data Transformation Services. Develop and Manage DTS Packages Several tools are included to make DTS a straightforward procedure. The DTS Import/Export Wizard is one such tool. This is included to help in the creation of DTS packages in order to import, export, or transform data. This can also aid in the copying of database components. The DTS Import/Export Wizard is the easiest way to copy data from one source to another. Included in its functionality is the ability to create the destination table if it does not already exist. Another included tool is the DTS Designer, which allows you to graphically create packages that incorporate such methods as event-driven logic, complex workflows, and multiple connections. The DTS Designer also allows modification of DTS packages created with the import/export wizard. You can build SQL Queries with the DTS Designer using the Data Transformation Services Query Designer. Within the DTS Query Designer, you have access to any database, including any linked servers that may be defined. There are a number of synchronized panes that allow you to build your SQL query in any number of ways. Each pane will reflect the changes made to another pane. This allows you to design your query in the easiest possible way. The Table/View List Pane allows you to see all of your tables and views associated with the currently selected database. If you change databases, the pane will refresh automatically, allowing you to view the new databases’ views and tables. This pane can be used to build an SQL Query simply by first selecting the table(s) and/or view(s) you wish to use. Then drag them to the Diagram Pane. The next pane is the Diagram Pane. The Diagram Pane is where you can view the database schema. It has rectangles representing the individual tables. Columns available in the table are listed. Lines representing joins link the tables or table- structured objects. Icons are shown representing how each column is being used. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 20
  22. 22. Microsoft SQL Server 2000 Administration Following the Diagram Pane is the Grid Pane. This pane is a grid, resembling a spreadsheet in which you can specify things such as columns and rows, and how rows should be grouped. The SQL Pane allows you to view the SQL query as you design it. You can edit it here, or enter your own SQL query. Queries such as Union queries cannot be created anywhere other than the SQL Pane. The final pane is the Results Pane. This is where you can view the result set of the last executed SQL query. The results are in a grid format. You can also modify the data in the database through the Results Pane simply by editing the data in the grid cells. You can also programmatically accomplish DTS Package creation using the DTS Object Module in a development platform such as Microsoft’s Visual Basic or Microsoft’s Visual C++. This will allow a greater degree of control. DTS Packages created in either the DTS Designer in SQL Server Enterprise Manager or the DTS Import/Export Wizard can be saved as a Visual Basic program and then modified through Microsoft’s Visual Studio software package. Bulk Insert Task DTS can also be used to accomplish certain tasks. One such task is the Bulk Insert Task. The Bulk Insert Task will take a tab-delimited text file and insert it into the database. This is used for large amounts of data. Data cannot be transformed during a Bulk Insert Task. If you wish to transfer data from one database system to another, it must first be exported into a text file. The destination for the insert must be an SQL server created table or view. If data exists in the destination table or view, the Bulk Insert data will be appended to the existing data. The server runs the Bulk Insert Task, so other processes in progress on the server will affect processing execution. Also, the server needs to have rights to both the source file and the destination table, regardless of their location. Path names must take into consideration that they need to come from the server. Another consideration be taken into account, is that only the members of the sysadmin role may execute the Bulk Insert Task. Bulk Copy Program Another task you can execute through DTS is the Copy SQL Server Objects Task. This task will copy objects from one SQL Server installation to another. Restrictions are that this will only copy objects from SQL Server 7.0 to SQL Server 7.0, SQL Server 7.0 to SQL Server 2000, and SQL Server 2000 to SQL Server 2000. When copying an object such as a table or view, the task will also copy any table or view © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 21
  23. 23. Microsoft SQL Server 2000 Administration that has a foreign key on the original table. When copying a table to a pre-existing table, you can select to overwrite or append to the existing data. You can also choose to drop the existing table and re-create it. Other than tables and view, objects that can be copied include stored procedures, indexes, data, and referential integrity constraints. Once DTS Packages have been created through any of the previously mentioned methods, you can manage and maintain them through the DTS Designer in Enterprise Manager. You can view and monitor things such as Microsoft Windows events, different transactions, any errors that have occurred, global variables used within the package, and package Identifiers. There is also an option called Disconnected Edit, which will allow you to edit properties of the DTS package that may not be available otherwise. This enables you to modify a package to run in a different environment than the one the package was originally created for. Data Type Conversion There are two types of Data Type conversions possible in Transact-SQL: • Implicit • Explicit Implicit Conversion Implicit conversion is done when two data types are compared to one another, moved from one data type field to a different data type field, or are combined from two different data types. For example, if you were to compare a numeric integer field to a string field, during the comparison one of the fields would be converted to the data type of the other, depending on the comparison. This type of conversion would also be done if you were to move a field, such as a numeric field to a string field. This type of conversion is also done when you move data from Transact-SQL to a program variable. This would be done if the data came from a results table, return code or output variable. The data would be converted into the data type of the program variable. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 22
  24. 24. Microsoft SQL Server 2000 Administration Explicit Conversion The second type of conversion is known as an Explicit Conversion. This is when you specifically convert a value from one data type to another for processing purposes. This is done using either the Cast or Convert statements. It is preferable to use the Cast statement, which is developed from the SQL-92 Standard, instead of the Convert statement. An example of this would be converting a numeric value into a varchar format. This is an example of the Cast statement, “CAST ( int AS VARCHAR(10) )”. Replication Services – Configuration, Troubleshooting, and Maintenance From SQL Server 7.0 to SQL Server 2000, Replication has remained largely the same. Within SQL Server 2000 there are three types of Replication: • Snapshot • Transactional • Merge Snapshot Replication Snapshot Replication takes an exact copy of data and database objects as they appear at a given moment, and distributes them. The Publisher, or the computer that makes data available will send the snapshot to either a Distributor or Subscriber. A Distributor is a computer containing the system tables for replication, including replication histories, and transactions, for transactional replication. The Distributor can be the same computer as the Publisher. The Subscriber is the computer receiving the data distributed by the Distributor. Replication can be set up as a Push subscription, which means that the Publisher will send out an updated replication at a scheduled time. Replication can also be set up as a Pull subscription, which means that the Subscriber will call for a new replication. Pull subscriptions work well for mobile subscribers who may not be available for replication at a scheduled time for a push subscription. Snapshot replication is useful for small data volumes, or in a situation where updates do not have to be done often and a bigger time difference between systems is allowable. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 23
  25. 25. Microsoft SQL Server 2000 Administration Transactional Replication With transactional replication, a snapshot of the system is sent to the subscriber. This will be the base from which the replication will continue. From there, every time data is changed on the publisher, it will be distributed to the subscriber. Insert statements, Update statements, and Delete statements will be monitored for changes, as well as modifications made to stored procedures, indexes, and views. Transactions can be propagated either instantaneously or at scheduled points in time. Propagation of data is done while preserving Transaction Boundaries. This means that if a transaction has ‘x’ amount of rows modified, then all affected rows will be propagated, or none of them will be. Transactional replication is good for systems that are most often connected. It is also good for systems that cannot have high latency in subscriptions. When all changes are distributed, all of the subscribers will have the same data as the publisher. Merge Replication This form of replication is used when you have various systems working both online and offline while making modifications to the data. At a later point in time, the data can be sent from different systems to update one complete system. Then the changes are propagated throughout all the subscribers. This type of replication can cause conflicts with data, thanks to multiple modifications from different systems before replication. Multiple choices exist, both default and custom, in order to resolve data conflicts. When such a conflict does occur, the Merge Agent executes these resolvers in order to determine which data modifications are kept. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 24
  26. 26. Microsoft SQL Server 2000 Administration Managing and Monitoring SQL Server 2000 Security Create and Manage Log Ons The first step in managing security for SQL Server 2000 is to determine how users log in. There are two methods used for this: • Windows Authentication • SQL Server login Windows Authentication With Windows Authentication, you create a login to SQL Server that corresponds to a Windows login account. This can be used on an all Windows networks. Using this method creates a mapping in the sysxlogins, which corresponds to a Windows login account. If a user does not authenticate to Windows, they will not be allowed to login to SQL Server. Something to keep in mind is that a valid login to SQL Server does not determine permissions on the various databases. Those permissions are configured separately. A user may be allowed to login to SQL Server but may not be allowed to access certain databases. SQL Server Logins The second method of authenticating SQL Server logins is to create a separate, specific SQL Server login. The user would log into Windows under one account and then into SQL Server under another, separate account. This is also useful for users who are not able to authenticate to Windows, such as a user on a Unix or Netware account. For an overview of SQL Server 2000 security, check out this page, Microsoft SQL Server 2000 Security. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 25
  27. 27. Microsoft SQL Server 2000 Administration Create and Manage Database Users During SQL Server installation, two SQL Server only accounts are created: • Sa • BUILTIN/Administrator For the sa account, the default password is blank. It is very important to issue a password for this account for security purposes. This account is a super user and has access to all of SQL Server. To leave the password blank is to leave open a serious vulnerability in SQL Server’s security. The BUILTIN/Administrator account allows any valid Windows Administrator to access SQL Server. This means that logging into any Windows NT or 2000 machine as a network or machine Administrator would grant access to SQL Server without a separate login. Database Access Database access is granted separately from SQL Server logins. For each database, using either Enterprise Manager or the stored procedure sp_grantdbaccess, you must create logins. The logins to the database do not have to be the same as the login to SQL Server, but administration of the system is easier if they are. You can remove logins from any database by executing the stored procedure sp_revokedbaccess. You can add a Guest user account to any database you wish, applying whichever permissions meet your needs. This account enables someone who is able to login to SQL Server, but does not have a login to the database, to login as a guest. If the guest account does not exist, then the user cannot log into that database without an account. The guest account must exist in the Master and Tempdb databases, although it is optional everywhere else. This account is not added by default, but will be added to all new databases if it is added to the Model database. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 26
  28. 28. Microsoft SQL Server 2000 Administration Create and Manage Security Roles Within SQL Server 2000 are four types of roles. A Role is similar to a Windows 2000 Group. These roles are: • Fixed Server • Fixed Database • User-Defined Database • Application Fixed Server Role This includes most of the administrative roles. Administrative roles include roles such as sysadmin, which allows a user to perform any action. Also included are roles such as dbcreator, which allows a user to create and alter databases. Fixed Database Role This includes all database roles such as db_owner, which allows all database role activities to be performed. Also included in Fixed Database roles is the role of db_denydatareader, which allows you to block a person from reading any data in any table. Another role is db_backupoperator, which gives a user the privileges to back up the database. User-Defined Role This is used for people who do not have the right to manage Windows accounts. This type of role is also used when you have a group of people who need to perform the same type of activity within SQL Server. Application Role This type of role is used by an application that accesses the SQL Server. The only privileges issued to a user are those privileges given to the application. The user launches the application and performs all activities through the application. If the application needs to access data in a different database, the application is given the rights of the Guest account. If these rights are insufficient for the activities the application is trying to perform, the application will be denied access to the database. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 27
  29. 29. Microsoft SQL Server 2000 Administration Database Permissions Permissions assigned to a user for various databases are cumulative. The only time permissions are not cumulative is when a permission is denied explicitly. Permissions known as Implicit Permissions are permissions assigned when a user is added to a role, or is the database owner. These permissions are not viewable, directly. Database owners are implicitly assigned all permissions on their created objects. Database owners are also allowed to grant, revoke, or deny permissions to anyone with access to SQL Server. Owners of Database Objects can grant, revoke and deny permissions to anyone, including Database Owners, to these objects. There are three types of permissions that apply to SQL Server: • Statement • Object • Predefined Statement Permissions This type of permission allows a user to execute statements through Transact-SQL. This would include the create statements, such as Create Table, or Create Database. This would also include the backup statements such as backup database or backup log. Object Permissions These permissions allow a user to do something, such as execute a Stored Procedure. They also allow users to view information or update information. Predefined Permissions These permissions apply to database and database object owners, as well as fixed roles. When you Grant permissions to a user, it means that the user can perform an action. When you Deny permissions to a user, it means that the user cannot perform an action and this cannot be overridden. When you Revoke permissions from a user, it means that the user cannot perform an action but this can be overridden. When granting users permissions to views, you do not have to grant permissions to the tables making up the views. Also, when a user has been granted Execute © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 28
  30. 30. Microsoft SQL Server 2000 Administration permissions on a stored procedure, they do not need permissions to modify or view the data that the stored procedure will access. SQL Server 2000 Management, Monitoring and Troubleshooting Create, Manage, and Troubleshoot SQL Server Agent Jobs One of the options available to you in SQL Server is the SQL Server Agent. You can create jobs for the agent to perform. These can be simple jobs such as backing up a database, or more complex jobs, such as executing stored procedures to clean up your database to increase performance. One method of creating these jobs is to go into the SQL Server Enterprise Manager. Expand your tree, and underneath your chosen server, select the Management folder. Expand that and you will find an SQL Server Agent option. If this icon has a red square on it, the agent is not running. If there is a green arrow, then the agent is running. The status of this icon is important because if the agent is not running, it will not perform its jobs. Configure Alerts and Operators by Using SQL Server Agents When you expand the SQL Server Agent tree, you will find three options. These options are: • Alerts • Operators • Error codes Alerts These are alerts you can configure so that when SQL Server meets a predefined condition, the SQL Server Agent will send an alert. This can be done in one of, or all three, methods. One way is by sending email. The second way is by sending a network alert, or net send, to a specified machine, or login account, which will follow a user, regardless of which machine they log into. The third way is to have SQL Server send the alert to a pager. Obviously for this to work the server must have a modem installed and configured. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 29
  31. 31. Microsoft SQL Server 2000 Administration Operators To send an alert either by email or network message, you must have a configured Operator to receive these alerts. The Operator is specified by a given name, and it does not have to be the same as their login account. You would specify their email account for them to be able to receive emails. You would enter their pager number as you would dial it normally, from a phone line in the same location. And you enter their net send address. This is all done on the General tab. You would also schedule when the pager is active, if you were using a pager. You may require someone to wear a pager at all times, or you may only require it during working hours. Error Codes On the Notifications tab, you would specify which error code uses each type of alert. A user defined error must be over the number, 50000. The standard error codes, 19 – 25, are written to the Windows Event Logs. Alerts that have been sent are also stored in the msdb.sysalerts table. For a given error, you may decide that it is not severe, so email is sufficient. However, for a severe error, you might choose to have all alerts sent: email, net send, and to a pager. Both are possible, as well as any combination of either. One recommendation is that the operators are defined before the alerts, since the alerts require an operator. Requirements for email alerts are that you have a MAPI- 1 compliant email client installed on the server. It would need to be configured for the system login account for this to work. Paging Alert A requirement for the paging alert is that you have a third party package that handles pager-to-email. This can be software or hardware. The only requirement for the net send alert is that the target and the server are running on the Windows NT or Windows 2000 platforms. A recommended procedure is that you configure a “Fail-safe” operator. This would be an operator who is alerted through one of the methods in the event the first operator did not answer the alert. If you have designated multiple people to be paged for an alert, and their pages all fail, the fail- safe operator will be notified. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 30
  32. 32. Microsoft SQL Server 2000 Administration Configuring Jobs for SQL Agent When configuring a job for the SQL Agent, you can select Jobs underneath the SQL Agent tree. Then you can either select Action > New Job from the menu bar, or right-click and select New Job from the popup menu. On the General tab of the new job window you can name the job. This should be descriptive of what it does. An example would be “Weekly Database Maintenance”. Under the Category drop down list, you can select from various replication and maintenance functions. The Owner would be whoever logged into SQL Server, or a valid user account with permissions to perform the action. You can also enter a Description. There is also an option where you can determine which server, or multiple servers for the SQL Agent to perform the job on. The next tab is the Steps tab. This is where you will create each step of the job to be performed. This is done by building Transact-SQL statements. Some steps will require that the previous step or steps were successful. This can be programmed into the steps. Following the steps portion of the job, you would create the Schedule. How often does the job need to run? You can also add alerts to your job, by adding specific error codes for each step of the job. Finally, on the Notifications tab you can decide whether to email, page, or net send an operator. You simply check off the type of notification you want, and pick the operator from a drop down list. You can also determine the condition for the alert, such as when the job fails, or if the job succeeds. As well, you can set the notification to alert the operator whenever the job completes, regardless of whether or not it succeeds. If for some reason the SQL Server Agent job fails, you can find logs in the directory: C:Program FilesMicrosoft SQL ServerMssqlLogErrorlog These logs will tell you the reason for the failure. You can also find the job history in the msdb database, in the sysjobhistory table. The job itself is kept in the sysjobs table. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 31
  33. 33. Microsoft SQL Server 2000 Administration Optimizing Hardware Resources and Usage For server performance tracking and bottleneck issues, you would look at five key areas specifically: • Memory usage • CPU processor utilization • Disk I/O performance • User connections • Blocking locks Memory Usage If a server has insufficient memory or has allocated insufficient memory to SQL Server, then performance will decrease. With insufficient memory installed or allocated, data will be read from the disk continuously instead of being stored in memory. Also Windows NT and 2000 will use the page file excessively for swapping the data to disk and back. CPU Processor Utilization If the CPU were not powerful enough to handle the load on the server, you would find a consistently high rate of CPU usage. At that point you would want to consider adding multiple processors or upgrading the current processor. Disk I/O Performance If your disk is slow, you will find degradation of transaction throughput. This can be resolved with a faster disk with faster read/write capabilities. User Connections If the number of users is not configured properly, or the users themselves are not configured properly, these items will diminish the memory available to SQL Server and may make the system run slower than normal. Blocking Locks If a process is being executed and forcing other processes to wait, or is being forced to wait itself because of blocking locks, then the system will be slowed down or will stop the blocked process entirely. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 32
  34. 34. Microsoft SQL Server 2000 Administration Monitoring Hardware Resources and Resolving System Bottlenecks To avoid these 5 bottleneck areas, you can use the Windows System Monitor to keep an eye on your hardware resources and usage. For example, to determine whether or not your CPU is being over-used and is in need of an upgrade, you would monitor the Processor: % Processor Time counter. If the CPU is experiencing excessively and consistently high utilization, then it may be a cause of bottlenecks. As a second example, if you wanted to determine if your system has enough memory to perform properly, you would use the System Monitor to watch the counters Memory: Available Bytes and Memory: Pages/sec. If the counter for Pages/sec shows a high value, excessive or slow paging to the disk may be the cause of the bottleneck. An application or process that does not release memory, or runs on a system with insufficient memory, can cause the Available Bytes counter to show a low value. Optimizing and Troubleshooting SQL Server System Activity When referring to SQL Server System Activity, this includes such activities as cache hits, connections, and locks. Also included are memory allocations, recompilation, and transactional throughput. To see a list of available configuration options, execute the stored procedure sp_configure. You can use the “Show advanced options” option to see the advanced options of sp_configure. There are several relevant tuning options, including Max worker threads, Parallel Query Options, Min Server Memory, Min Memory Per Query, Max Server Memory, and Max Async IO. Monitoring SQL Server Activity by Using Traces You can monitor SQL Server system activity by using traces. The first step in creating a trace is to capture the data columns Event Class, ClientProcessID, and Start Time. You can also capture any other data column you wish to add to the trace. You can capture the trace to a file or a table, sorted by Event Class. If the trace is captured to a file, it can be opened while being written to, so long as it is not running on a Windows 95 or Windows 98 machine. The second step is to find the events you have targeted for tracing. For example, if you captured the trace to a table, you would open the trace table, and expand the particular event class that contains the events. Take notice of the ClientProcessID and Start Time of the events you are tracing. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 33
  35. 35. Microsoft SQL Server 2000 Administration In the third step, you display the traced events sorted by ClientProcessID instead of the Event Class. They will be in chronological order based on Start Time. You can also use the same methods to find events sorted by Server Name, Database ID, or Object ID. Monitoring SQL Server Activity by Using System Monitor You can also use Windows System Monitor to view SQL Server system activity. It can provide you with information on activity and performance statistics, right up to the second. It can also provide information from multiple computers simultaneously. You can set up the System Monitor to reflect counters that will be updated at a frequency determined by the user. You have the ability to create log files, which can contain data from different computers on various objects. You can export logs, counters, and alert logs to spreadsheets and databases. This allows you to reorganize, print, and manipulate the data, as you desire. The System Monitor can be set to alert you with a network message or by switching to an Alert view, whenever a certain event takes place. It can also be set to write the alert to an alert log, for later review. Reports can be created from existing log files, or viewed as current activity reports. A long-term archive can be formed simply by appending selected sections of existing logs to one single file. Another function of the Windows System Monitor is being able to launch a predefined application at a preset time. When an event occurs, you can launch the application. This can be done the first time, or every time a set counter either drops below, or rises above, a preset value. Finally, you can save settings for the chart, counter, log, or report settings individually, or you can save the entire workspace, to be reused at a later time. Special thanks to Thomas W. Fritts Jr. for contributing this Cramsession. © 2002 All Rights Reserved – BrainBuzz.com 04/25/02 34

×