Tải bản đầy đủ (.pdf) (66 trang)

Backup And Recovery In SQL Server Collaborate

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (1.31 MB, 66 trang )

LESSON 3C
COLLABORATE

3C. 1

Administering and Troubleshooting SQL Server 2000


INSTRUCTOR NOTES
In this section, tell students about the concept of Object Linking and Embedded
databases (OLEDB). OLEDB is a set of Application Programming Interfaces (APIs) that
enables the user to connect to different data sources.
Ensure that the following datafiles are installed on the student nodes:

„Employee.mdb
„BooksDetails.xls

Administering and Troubleshooting SQL Server 2000

3C.2


KNOWLEDGE BYTE

Collaborate

Knowledge Byte
In this lesson, you will learn about:





monitor SQL Server system activity using System Monitor
optimize and troubleshoot SQL Server system activities

©NIIT

Collaborate

Lesson 3C / Slide 1 of 34

In this section, you will learn to:

„monitor SQL Server system activity using System Monitor.
„optimize and troubleshoot SQL Server system activities.

3C.3

Administering and Troubleshooting SQL Server 2000


Creating a link between SQL Server 2000 and a
OLE DB Provider
Collaborate

Creating a link between SQL Server
2000 and a OLE DB Provider


©NIIT


Sandra is a database administrator at Bluemun Inc. The company has
its branch offices at various locations in the US. These branches use
SQL Server 2000 to manage database. The company has recently
opened two new branch offices at New Jersey and California. The branch
managers of these branches have been maintaining data in Access and
Excel as they do not have SQL Server installed. . The head office
collects the sales reports from all its branch offices and updates the
central database data on a weekly basis. The two new branch offices
have sent sales reports in Access and Excel data formats. Therefore,
Sandra needs to copy data from these database files to the SQL Server
database.

Collaborate

Lesson 3C / Slide 2 of 34

Administering and Troubleshooting SQL Server 2000

3C.4


Collaborate

Creating a link between SQL Server
2000 and a OLE DB Provider (Contd.)


©NIIT

3C.5


To copy data from Access and Excel into SQL Server database, Sandra
needs to create a link server using Object Linking and Embedded
databases (OLEDB). OLEDB uses the data provider and data source
arguments to connect to various databases. The table below describes
various data sources and data providers:

Product

Data Source

Data Provider

MS Access

MS Access

MS Access

Oracle System
Identifier

Oracle System
Identifier

Oracle System
Identifier

MS Jet 4.0 OLE DB


MS Jet 4.0 OLE DB

MS Jet 4.0 OLE DB

Collaborate

Lesson 3C / Slide 3 of 34

Administering and Troubleshooting SQL Server 2000


Sandra is a database administrator at Bluemun Inc. The company has its branch
offices at various locations in the US. These branches use SQL Server 2000 to manage
database. The company has recently opened two new branch offices at New Jersey
and California. The branch managers of these branches have been maintaining data in
Access and Excel as they do not have SQL Server installed. The head office collects
the weekly sales reports from all its branch offices and updates the data on the central
database. The two new branch offices have sent sales reports in Access and Excel data
formats. Therefore, Sandra needs to copy data from these database files to the SQL
Server database.
To copy data from Access and Excel into SQL Server database, Sandra needs to create
a link server using Object Linking and Embedded databases (OLEDB). OLEDB uses the
data provider and data source arguments to connect to various databases. Data
provider specifies the provider name and the type of data to retrieve. For example,
SQLOLEDB.1 is the name of the Microsoft OLEDB Provider for SQL Server. Data source
specifies the name of the database to which the data provider connects.
The table below describes the provider name and data sources of the different
databases:

Product


Data Source

Data Provider

MS Access

Database File
Location

MS Jet 4.0 OLE
DB

Excel

Spreadsheet File
Location

MS Jet 4.0 OLE
DB

Oracle

Oracle System
Identifier

MS OLE Provider
for Oracle

Sandra would need to create linked servers between SQL Server and Access and

Excel, to enable data access from heterogeneous databases. After creating linked
servers, the data from Access and Excel appear as tables in SQL Server Enterprise
Manager.
You will now look at the steps to create a link between:

„Excel and SQL Server
„Access and SQL Server

Administering and Troubleshooting SQL Server 2000

3C.6


Creating a link to Microsoft Excel

Collaborate

Creating a link to Microsoft Excel

1.
2.

©NIIT

The process to create a link between SQL Server and Microsoft Excel
involves following steps:
Specify range of cells for linking
Creating a Linked server using T-SQL

Collaborate


Lesson 3C / Slide 4 of 34

The process to create a link between SQL Server and Microsoft Excel involves following
steps:
1. Specifying range of cells for linking
2. Creating a Linked server using T-SQL

1. Specifying the range of cells for linking
To specify the range of cells in the BookDetails Excel file sheet that would be linked
to SQL Server perform the following steps:
1. Open BookDetails in Microsoft Excel. Click the InsertÆNameÆDefine
option, to open the Define Name dialog box.

3C.7

Administering and Troubleshooting SQL Server 2000


2. Next, you need to specify the name of the selected cells in the workbook that
you want to link in the Define Name dialog box. Specify the name of the
selected cells as Book in the Names in workbook text box, as shown.

3. Click the Refers to textbox to specify the range of cells that you need to
copy. Drag the cursor to select the range area on the Excel workbook. A range
identifies a cell or a group of cells in an Excel workbook.

Administering and Troubleshooting SQL Server 2000

3C.8



4. Click the Add button in the Define Name dialog box to define the new name
for the selected range of cells.
5. Click the OK button in the Define Name dialog box to complete the process.
6. Save the changes made to the Excel workbook.
You have successfully named a range of cells from the workbook that need to be
linked to SQL Server.

2. Creating a Linked Server Using T-SQL
After specifying the range of cells, you need to create a linked server to connect the
range of cells in Excel with SQL Server.
To create a linked server, you need to perform the following steps:
1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆQuery Analyzer to
start SQL Query Analyzer.
2. Notice that the Connect to SQL Server dialog box appears. Select the
SERVER option from the SQL Server drop-down list and click the OK button
to connect to the SQL Server.

3. The SQL Query Analyzer is opened.

3C.9

Administering and Troubleshooting SQL Server 2000


4. The syntax for creating a linked server with Excel worksheet is shown below.
execute sp_addlinkedserver
@server = '<Excel worksheet name>',
@srvproduct= 'Excel',

@provider='Microsoft.Jet.OLEDB.4.0',
@datasrc='<Path of the Excel file>',
@provstr='<Version of Excel>'
Type the code in the SQL Query Analyzer window, as shown.

Execute Query
Button

5. To execute the query, click the Execute Query button on the toolbar. SQL
Server will display a successful message, as shown.

Administering and Troubleshooting SQL Server 2000

3C.10


6. Close the SQL Query Analyzer window.
After creating a linked server, verify if the tables are available in SQL Server. Perform
the following steps, to verify the link between Excel and SQL Server.
1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆEnterprise Manager,
to open the Enterprise Manager window.
2. In the Enterprise Manager window, under the Console Root, expand the
default server. Under the database server expand the Security option, as
shown.

3C.11

Administering and Troubleshooting SQL Server 2000



3. Click the Linked Servers option to view the linked servers.
4. Expand the linked server, BOOKDETAILS to list the available objects in the
server, as shown.

Administering and Troubleshooting SQL Server 2000

3C.12


5. Click the Tables option, to view the named ranges as tables. The named
ranges appear as tables in Enterprise Manager, as shown.

3C.13

Administering and Troubleshooting SQL Server 2000


You have successfully created a linked server between the named cell, Book, in Excel
and SQL Server.

Administering and Troubleshooting SQL Server 2000

3C.14


Creating a link to MS Access

Collaborate

Creating a link to MS Access




©NIIT

Sandra also needs to create a link between the data in Access and SQL
Server to compile the sales report sent by the other branch office.
Sandra can use sp_addlinkedserver stored procedure to create a linked
server.

Collaborate

Lesson 3C / Slide 5 of 34

Sandra also needs to create a link between the data in Access and SQL Server to
compile the sales report sent by the other branch office.
You need to perform the following steps to link the data in Access with SQL Server:
1. Open Microsoft Access and create a new mdb file, Books.mdb.

3C.15

Administering and Troubleshooting SQL Server 2000


2. Next, you need to create a new table, Suppliers, in the books.mdb database.
Create the table with the following fields: Supplierid, Suppliername,
Contactname, Address, City, Phonenumber, Emailaddress, where Supplierid is
the primary key, as shown.

Administering and Troubleshooting SQL Server 2000


3C.16


3. After creating the database in MS Access, close the application.
4. Open the SQL Query Analyzer window.
5. The syntax for creating a linked server with the Access database is:
execute sp_addlinkedserver
'<database name>',
'Access 2000',
'Microsoft.Jet.OLEDB.4.0',
'<database path>'

3C.17

Administering and Troubleshooting SQL Server 2000


6. Type the following code in the SQL Query Analyzer window, to create a linked
server, as shown.

7. Click the Execute Query button on the Query Analyzer window toolbar to
execute the query. SQL Server displays a successful message in the message
window of SQL Query Analyzer, as shown.

Administering and Troubleshooting SQL Server 2000

3C.18



8. Finally, close the SQL Query Analyzer window.
After creating a linked server, verify if the tables are available in SQL Server. Perform
the following steps, to verify the link between Access and SQL Server.
1. Select StartÆAll ProgramsÆMicrosoft SQL ServerÆEnterprise Manager,
to open the Enterprise Manager window.
2. In the Enterprise Manager window, expand database server. Under database
server, expand the Security option.
3. Click the Linked Server option to view the linked servers.
4. Expand the linked server, Books to view the objects.
5. Click the Tables option, to view the tables. Notice that data in MS Access
appear as tables in SQL Server Enterprise Manager.

3C.19

Administering and Troubleshooting SQL Server 2000


You have successfully created a linked server between the table, Suppliers, in the
Books database in Access and SQL Server.

Administering and Troubleshooting SQL Server 2000

3C.20


Alternative Methods to Monitor SQL Server
System Activity

Collaborate


Alternative Methods to Monitor SQL
Server System Activity


©NIIT

3C.21

A database administrator can use the Task Manager to monitor SQL
Server system activities. In addition, a database administrator can use
the following tools provided by SQL Server 2000, to monitor SQL
Server system activities and performance of SQL Server 2000:
• Query Analyzer
• SQL Profiler
• SQL Server Enterprise Manager
• Transact-SQL

Collaborate

Lesson 3C / Slide 6 of 34

Administering and Troubleshooting SQL Server 2000


A database administrator can use the Task Manager to monitor SQL Server system
activities. In addition, a database administrator can use the following tools provided
by SQL Server 2000, to monitor SQL Server system activities and performance of
SQL Server 2000:

„Query Analyzer

„SQL Profiler
„SQL Server Enterprise Manager
„Transact-SQL Statements
Using Query Analyzer to Monitor SQL Server 2000
System Activity

Collaborate

Using Query Analyzer to Monitor SQL
Server 2000 System Activity




©NIIT

As a database administrator, you need to monitor the execution of
queries to determine the performance of SQL Server 2000 with respect
to the response time of the query. The execution of a query is
monitored using an Execution plan. An Execution plan is a graphical
display of the execution steps of a query. It also displays the various
system resources that are used during the execution of the query.
Using the information displayed in the execution plan you can monitor
execution of the queries, identify possible problems areas, and
implement techniques to improve query processing and reduce the
response time.

Collaborate

Lesson 3C / Slide 7 of 34


As a database administrator, you need to monitor the execution of queries to
determine the performance of SQL Server 2000 with respect to the response time of
the query. The execution of a query is monitored using an Execution plan. An
Execution plan is a graphical display of the execution steps of a query. It also displays
the various system resources that are used during the execution of the query.

Administering and Troubleshooting SQL Server 2000

3C.22


The following are the steps to monitor the execution of a query using the Query
Analyzer:
1. Select StartÆ All ProgramsÆ Microsoft SQL ServerÆ Query Analyzer, to
open the SQL Query Analyzer window.
2. Select the Northwind database from the database drop-down list on the tool
bar, as shown.

3. Type the following code in the SQL Query Analyzer window, to view the
execution plan of the query, as shown.

3C.23

Administering and Troubleshooting SQL Server 2000


4. Click the Execute Query button on the Query Analyzer window toolbar to
execute the query.
5. The result of the query is displayed in the message window of SQL Query

Analyzer, as shown.

Administering and Troubleshooting SQL Server 2000

3C.24


6. Select QueryÆ Show Execution Plan and execute the query again to view
the execution plan of the query.

7. Click the Execution Plan tab page in the result pane of the SQL Query
Analyzer window. The execution plan of the query is displayed in the Execution
Plan tab page of the result pane, as shown.

3C.25

Administering and Troubleshooting SQL Server 2000


×