Microsoft SQL Server 7.0 System Administration Training Kit

[Previous] [Next]

The rest of this book describes how you will manage and administer SQL Server. You will use SQL Server Enterprise Manager and SQL Server Query Analyzer for most administrative tasks. This lesson introduces these two important tools.

After this lesson, you will be able to

Estimated lesson time: 60 minutes

SQL Server Activities

SQL Server activities generally fall into one of two categories: implementing a SQL Server database, which is often the job of a developer, and administering a SQL Server database. This section lists some of the tasks involved in each of these categories. The focus of this book is on administering a SQL Server database.

Implementing a SQL Server Database

Implementing a SQL Server database means planning, creating, and maintaining a number of interrelated components.

The nature and complexity of a database application, as well as the process of planning it, can vary greatly. For example, a database can be relatively simple, designed for use by a single person, or it can be large and complex, designed to handle all the banking transactions for hundreds of thousands of clients.

Regardless of the size and complexity of the database, implementing a database usually involves

This book does not cover these database implementation activities.

Administering a SQL Server Database

Administering a SQL Server database involves

Client/Server Tools

All of the SQL Server administrative tools are clients. They connect to the SQL Server service (MSSQLServer) just as user applications do. This is always true, whether the administrative tools are running on the SQL Server computer or on another computer on a network. The SQL Server service takes a number of startup parameters. Other than these startup parameters, the only way to interact with the SQL Server service is by making a client connection and sending Transact-SQL commands. None of the tools interact directly with the database files.

The server has to be running for the tools to connect. If the server is not running, most of the administrative tools will show an error message; Enterprise Manager, however, can automatically start the server. When Enterprise Manager connects to the server, it uses the security settings saved in the server registration, so you are not prompted to log on. As you use the graphical interface, Enterprise Manager uses Transact-SQL and the SQL-DMO interface to communicate with the server.

Some database operations require that no other user be using the database when you perform the operation. As far as the server is concerned, each connection is completely independent, so it is possible for tools running on the same computer to interfere with each other. If you have Enterprise Manager and Query Analyzer open at the same time, you have at least two connections to SQL Server (more if you have more than one query window open in Query Analyzer). For example, if Query Analyzer is using a database and you try to perform an exclusive operation on that database with Enterprise Manager, the Query Analyzer connection will prevent the Enterprise Manager connection from gaining exclusive access to the database, and the operation will fail.

We will focus on the Enterprise Manager and the Query Analyzer in this section. Other client utilities available with SQL Server include the SQL Server Client Configuration tool, SQL Server Performance Monitor, SQL Server Profiler, SQL Server Setup, and SQL Server wizards.

SQL Server Enterprise Manager

Enterprise Manager is a server administration and database management client. It is a Microsoft Management Console (MMC) snap-in. MMC is a shared user interface for BackOffice server management that provides a convenient and consistent environment for administrative tools. One or more snap-ins are loaded and configured in MMC to create a console. Enterprise Manager is a preconfigured MMC console. It is possible to configure your own consoles that include other BackOffice or third-party snap-ins. The main parts of the Enterprise Manager window, shown in Figure 4.2, are as follows:

Figure 4.2 The main parts of the Enterprise Manager window

For a number of items that you select in the console tree, you can also view a taskpad in the details pane. A taskpad may present tasks related to the selected item or a summary report containing useful information and statistics about a SQL Server component. To switch between one of the icon views and the taskpad view, right-click the item in the console tree, point to View, and then click Taskpad. If there is no Taskpad option on the View menu, it means that there is no taskpad for that item. Taskpads are HTML pages, which may have links that you can click in the same way that you click a link on a Web page in your browser. For this reason, when you right-click in a taskpad, you will see the Internet Explorer pop-up menu, not the Enterprise Manager pop-up menu that you see when viewing one of the item views. Figure 4.4 shows the taskpad for a database.

Figure 4.4 The taskpad for a database

You often need to refresh views in Enterprise Manager to see the most up-to-date server information, especially if you execute Transact-SQL commands in Query Analyzer or other tools. Right-click an item in the console tree and click Refresh to refresh that item. If you want to quickly refresh everything, right-click your server and click Disconnect. When you expand your server again, Enterprise Manager makes a new connection to the server and retrieves fresh copies of all items. Note that the presence of a red zigzag line next to the server icon in the console tree indicates that you are connected to the server.

NOTE


In previous versions of SQL Server, Enterprise Manager had a query window in which you could execute interactive queries. Although Enterprise Manager no longer has its own query window, you can now launch Query Analyzer from the Tools menu to execute interactive queries.

Exercise: Using Enterprise Manager

In this exercise you will explore the main features of the Enterprise Manager interface to familiarize yourself with Enterprise Manager in preparation for the exercises in the rest of the book.

  1. Open Enterprise Manager.
  2. Expand SQL Server Group, then expand your server.
  3. Click your server in the console tree.
  4. Large icons are listed for the administrative folders on your server.

  5. Right-click your server in the console tree, point to View, and click Taskpad.
  6. The taskpad for your server is shown. Try clicking on some of the links in the taskpad, and notice that each one takes you to another page that lists links for managing an aspect of SQL Server.

  7. Expand your server, expand Databases, and click the Northwind database.
  8. Right-click the Northwind database, point to View, and click Taskpad.
  9. Review the information about the Northwind database.
  10. Click the Tables & Indexes link to see information about the size of the tables and indexes in the Northwind database.
  11. Expand Northwind, and click Tables.
  12. In the details pane, right-click the Products table, point to Open Table, and click Return All Rows.
  13. You will see an editable grid, which displays the contents of the Products table. The grid is part of the graphical query builder in Enterprise Manager. You can use the query builder to build and execute queries based on one or many tables.

  14. On the Tools menu, click SQL Server Configuration Properties. (You may need to close the table view before accessing the Tools menu.)
  15. Click the various tabs in the SQL Server Properties dialog box and review the properties for your server. Do not change any of the default values.
  16. On the Connections tab, note that the Maximum Concurrent User Connections option is set to 0. This means that SQL Server automatically configures the number of user connections, up to a maximum of 32,767. The Default Connection Options list allows you to configure ANSI defaults for user connections. When a client application connects to SQL Server, data sent between the client and the server can be formatted in a number of ways. These options specify defaults for how data should be formatted. For example, SQL Server can accept or not accept identifiers, such as database or table names, that are enclosed in double quotes (Quoted Identifier). These defaults can be overridden by clients.

    On the Memory tab, note that SQL Server is set to dynamically control memory usage.

  17. Click Cancel to close the SQL Server Properties dialog box without saving changes.

SQL Server Query Analyzer

SQL Server Query Analyzer is a graphical user interface for designing and testing Transact-SQL statements, batches, and scripts interactively.

NOTE


Query Analyzer replaces the ISQL/w tool found in previous versions of SQL Server.

Query Analyzer provides the following features:

The main parts of the Query Analyzer window, shown in Figure 4.5, are as follows:

You can open multiple query windows in Query Analyzer. This allows you to work in different databases or execute different scripts at the same time. Each window makes its own separate connection to the server (you can use different login credentials for different windows). These connections maintain different settings, and each has its own current database. If you try to perform an exclusive operation on a database from one window while another window is using the database, the operation will fail.

To open a new query window using the login credentials and settings of an existing window, select New Query from the Query menu. To open a new query window using different login credentials and default settings, select Connect from the File menu.

Notice the following when you use Query Analyzer:

The following table lists a number of useful keyboard shortcuts you can use in Query Analyzer.

Action Keyboard shortcut
Execute Ctrl-E or F5
Find Ctrl-F
Change selected text to uppercase Ctrl-Shift-U
Change selected text to lowercase Ctrl-Shift-L
Results In Text Ctrl-T
Results In Grid Ctrl-D
Help using Query Analyzer F1
Help with a selected Transact-SQL statement Shift-F1

Exercise: Using Query Analyzer

In this exercise you will use Query Analyzer and explore many of its features.

  1. Log on to Windows NT as Administrator or to another account that is a member of the local Administrators group.
  2. Open Query Analyzer from the Microsoft SQL Server 7.0 Programs Start menu. Connect to SQL Server using Windows NT authentication.
  3. In the query pane, type
  4. SELECT @@VERSION

  5. Click Execute Query on the toolbar. The query returns information in the results pane indicating the version of SQL Server and Windows NT that you are using.
  6. In the DB box, select Northwind. In the query pane, type
  7. SELECT * FROM Customers

  8. Click the Execute Query button on the toolbar. The query returns rows of data from the Customers table in the results pane. The output displays as free-form text.
  9. On the Query menu, click Results In Grid.
  10. Click the Execute Query button on the toolbar. The query returns rows of data from the Customers table in the results pane. The output is displayed in a grid.
  11. Click the Messages tab in the results pane. The results pane displays messages that were returned when the query was executed.
  12. In the DB box, select pubs. In the query pane, type
  13. EXEC sp_help

  14. Click the Execute Query button on the toolbar. The query returns information about the current database (pubs) in the results pane. There are now two results grids in the results pane, as the sp_help system stored procedure returns both a list of objects and a list of datatypes in the database.
  15. On the File menu, click Open. A dialog box warns you that you are going to lose the current contents of the query pane. Click No, as it is not necessary to save the changes in this case.
  16. Navigate to and open C:\Sqladmin\Exercise\Ch03\Savedqry.sql.
  17. Click the Parse Query button on the toolbar. An error message displays in the results pane, indicating that the query is invalid.
  18. Change the INNERJOIN clause on line 12 to INNER JOIN (add a space between INNER and JOIN). The change in the color coding indicates that the clause is now being recognized. Click the Parse Query button on the toolbar again. The message in the results pane now indicates that the query is valid. This does not necessarily mean that the query will execute, just that the syntax of the query is now correct.
  19. Click the Execute Query button on the toolbar. The results pane indicates that an error occurred when executing the query. Change the name Category on line 11 to CategoryName. Click the Execute Query button on the toolbar again. Two results grids and some messages are shown in the results pane.
  20. On the File menu, click Save to save the corrected query.
  21. Click the New Query button on the toolbar. A second query window opens. This query window opens a separate connection to the SQL Server.
  22. In the new query window, in the DB box, select master. This makes the master database the current database for the second query window. The Northwind database is still the current database for the first query window.
  23. In the new query window, in the query pane type
  24. SELECT * FROM sysdatabases

    (sysdatabases is a system table that you will learn about in the next section.)

  25. Click the Execute Query button on the toolbar. A list of the databases on the server is displayed in the results pane.

Lesson Summary

SQL Server 7 provides a number of client utilities to be used in the administration of a server and the implementation of a database. The Enterprise Manager provides a user-friendly interface with which an administrator can configure a SQL Server and build database objects. The Query Analyzer can be used for a number of tasks, including running queries against database tables, executing stored procedures that retrieve or modify information in a database, and executing system stored procedures that change or retrieve configuration settings.

Категории