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
- Describe SQL Server implementation and administration activities
- Describe how client/server tools are used to administer SQL Server
- Use SQL Server Enterprise Manager
- Use SQL Server Query Analyzer
Estimated lesson time: 60 minutes
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 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 involves
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.
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
Figure 4.3 The detail list view for a database
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.
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.
Large icons are listed for the administrative folders on your server.
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.
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.
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.
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:
Figure 4.5 The main parts of the Query Analyzer window
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 |
In this exercise you will use Query Analyzer and explore many of its features.
SELECT @@VERSION |
SELECT * FROM Customers |
EXEC sp_help |
SELECT * FROM sysdatabases |
(sysdatabases is a system table that you will learn about in the next section.)
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.