Administering and Troubleshooting SQL Server 2000 3C.4Creating a link between SQL Server 2000 and a OLE DB Provider Collaborate Lesson 3C / Slide 2 of 34 ©NIIT Collaborate Creating a li
Trang 1LESSON 3C
Trang 2Administering and Troubleshooting SQL Server 2000 3C.2
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
Trang 3In this lesson, you will learn about:
•monitor SQL Server system activity using System Monitor
•optimize and troubleshoot SQL Server system activities
In this section, you will learn to:
monitor SQL Server system activity using System Monitor
optimize and troubleshoot SQL Server system activities
Trang 4Administering and Troubleshooting SQL Server 2000 3C.4
Creating a link between SQL Server 2000 and a OLE DB Provider
Collaborate Lesson 3C / Slide 2 of 34
©NIIT
Collaborate
Creating a link between SQL Server
2000 and a OLE DB Provider
• 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
Trang 5Collaborate Lesson 3C / Slide 3 of 34
©NIIT
Collaborate
Creating a link between SQL Server
2000 and a OLE DB Provider (Contd.)
• 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:
MS Jet 4.0 OLE DB
MS Jet 4.0 OLE DB
MS Jet 4.0 OLE DB
Oracle System Identifier
Oracle System Identifier
Oracle System Identifier
MS Access
MS Access
MS Access
Data Provider Data Source
Product
Trang 6Administering and Troubleshooting SQL Server 2000 3C.6
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
Location MS Jet 4.0 OLE DB
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
Trang 7Creating a link to Microsoft Excel
Collaborate Lesson 3C / Slide 4 of 34
©NIIT
Collaborate
Creating a link to Microsoft Excel
• The process to create a link between SQL Server and Microsoft Excel involves following steps:
1. Specify range of cells for linking
2. Creating a Linked server using T-SQL
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
Trang 8Administering and Troubleshooting SQL Server 2000 3C.8
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
Trang 94 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
Trang 10Administering and Troubleshooting SQL Server 2000 3C.10
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
5 To execute the query, click the Execute Query button on the toolbar SQL
Server will display a successful message, as shown
Execute Query Button
Trang 116 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
Trang 12Administering and Troubleshooting SQL Server 2000 3C.12
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
Trang 135 Click the Tables option, to view the named ranges as tables The named
ranges appear as tables in Enterprise Manager, as shown
Trang 14Administering and Troubleshooting SQL Server 2000 3C.14
You have successfully created a linked server between the named cell, Book, in Excel and SQL Server
Trang 15Creating a link to MS Access
Collaborate Lesson 3C / Slide 5 of 34
©NIIT
Collaborate
Creating a link to MS Access
• 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.
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.
Trang 16Administering and Troubleshooting SQL Server 2000 3C.16
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
Trang 173 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>'
Trang 18Administering and Troubleshooting SQL Server 2000 3C.18
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
Trang 198 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.
Trang 20Administering and Troubleshooting SQL Server 2000 3C.20 You have successfully created a linked server between the table, Suppliers, in the
Books database in Access and SQL Server
Trang 21Alternative Methods to Monitor SQL Server System Activity
Collaborate Lesson 3C / Slide 6 of 34
• Query Analyzer
• SQL Profiler
• SQL Server Enterprise Manager
• Transact-SQL
Trang 22Administering and Troubleshooting SQL Server 2000 3C.22
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:
Using Query Analyzer to Monitor SQL
Server 2000 System Activity
• 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.
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
Trang 23The 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
Trang 24Administering and Troubleshooting SQL Server 2000 3C.24
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
Trang 256 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
Trang 26Administering and Troubleshooting SQL Server 2000 3C.26
Trang 278 The Execution Plan tab page of the result pane displays the execution plan of the query in a step-by step manner You can place the mouse pointer on each step to display the system resources used by the query during its execution,
as shown
Trang 28Administering and Troubleshooting SQL Server 2000 3C.28
Trang 29Using 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
Trang 30Administering and Troubleshooting SQL Server 2000 3C.30
Using SQL Profiler to Monitor SQL Server 2000 System Activity
Collaborate Lesson 3C / Slide 8 of 34
©NIIT
Collaborate
Using SQL Profiler to Monitor SQL
Server 2000 System Activity
• SQL Profiler is a graphical tool that is used to identify performance related problems of SQL Server 2000
• SQL Profiler uses the concept of Trace Templates to capture information related to specific server events
• Trace templates store information that can be used to monitor SQL Server system activity, identify stored procedures that take long time to execute, and identify deadlocks
Trang 31Collaborate Lesson 3C / Slide 9 of 34
©NIIT
Collaborate
Using SQL Profiler to Monitor SQL
Server 2000 System Activity (Contd.)
• The following table lists the various pre-configured templates provided by SQL Profiler:
2000 SQL Profiler uses the concept of Trace Templates to capture information related
to specific server events Trace templates store information that can be used to monitor SQL Server system activity, identify stored procedures that take long time to execute, and identify deadlocks
Trace templates are files with extension TRC SQL Profiler provides pre-configured trace templates that define the type of information to be captured and monitored
Trang 32Administering and Troubleshooting SQL Server 2000 3C.32
The following table lists the various pre-configured templates provided by SQL Profiler:
SQLProfilerSP_Counts Captures the number of stored procedures
that are executed and also captures the number of times each stored procedure has been executed
SQLProfilerStandards Captures general information regarding the
execution of SQL Server batches and stored procedures
SQLProfilerTSQL Captures each Transact-SQL statement
that has been executed in the specified order and the number of times each statement is executed
SQLProfilerTSQL_Duration Captures each Transact-SQL statement
that has been executed in the specified order and displays this information after arranging it on the basis of time taken to run a statement
SQLProfilerTSQL_Grouped Captures each Transact-SQL statement
that has been executed in the specified order and compiles this information according to the user issuing these statements
SQLProfilerTSQL_Replay Captures details about each Transact-SQL
statement executed in the specified order SQLProfilerTSQL_SPs Captures details about the execution of
each stored procedure, also including the Transact-SQL commands of each stored procedure
SQLProfilerTuning Captures information and binary data
about each stored procedure that is executed
Using these built-in templates and the information they capture, you can monitor specific server events, identify possible problem areas, and implement techniques to improve the performance of events
Trang 33Using Enterprise Manager to Monitor SQL Server System Activity
Collaborate Lesson 3C / Slide 10 of 34
©NIIT
Collaborate
Using Enterprise Manager to Monitor
SQL Server System Activity
• In addition, you can monitor SQL Server system activities using SQL Server 2000 Enterprise Manager Enterprise Manager provides the Current Activity option under the
Console RootÆMicrosoft SQL ServersÆSQL Server GroupÆDefault ServerÆManagement folder This displays detailed information regarding:
• currently active processes.
• user activity.
• locks held by each process.
• locks held on various objects