query analyser , sql server groups, transact –sql

31
Presentation on Query Analyser , SQL Server Groups, Transact –SQL

Upload: komal-batra

Post on 20-Jan-2015

79 views

Category:

Technology


6 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Query Analyser , SQL Server Groups, Transact –SQL

Presentation

on

Query Analyser , SQL Server Groups, Transact –SQL

Page 2: Query Analyser , SQL Server Groups, Transact –SQL

Query Analyzer

SQL Server Query Analyzer is a graphical user interface for designing and testing Transact-SQL statements, batches, and scripts interactively. It can be called from SQL Server Enterprise Manager. You can merge data from SQL 2000 databases, AS/400 tables or other DBMS using Distributed Query architecture.

Page 3: Query Analyser , SQL Server Groups, Transact –SQL

Microsoft SQL Server 2000 SQL Query Analyzer is a graphical tool that allows you to:

Create queries and other SQL scripts and execute them against SQL Server databases. (Query window)

Quickly create commonly used database objects from predefined scripts. (Templates)

Locate objects within databases (object search feature), or view and work with objects. (Object Browser)

Execute stored procedures without knowing the parameters. (Object Browser procedure execution feature)

Debug stored procedures. (T-SQL Debugger)

Debug query performance problems. (Show Execution Plan)

Page 4: Query Analyser , SQL Server Groups, Transact –SQL

Accessing Sql Query Analyzer

You can open Query Analyzer from Enterprise Manager by clicking Tools > Query Analyzer.

Page 5: Query Analyser , SQL Server Groups, Transact –SQL

SQL Query Analyzer looks like this:

Page 6: Query Analyser , SQL Server Groups, Transact –SQL

Query Menu ItemsThe Query menu items are grouped into several sections because they encompass different kinds of activities. . Several items, such as changing database context and parsing/executing queries, are also represented by default toolbar buttons

Page 7: Query Analyser , SQL Server Groups, Transact –SQL

Connection Properties

Page 8: Query Analyser , SQL Server Groups, Transact –SQL

Execution Plans

Displaying the execution plan shows you how SQL Server proposes to execute a specific query. There are usually a number of different ways that the desired results of a query can be achieved The execution plan shows you the decision that SQL Server has made about how to run the query most efficiently.

Page 9: Query Analyser , SQL Server Groups, Transact –SQL

Select * from Users u, Departments d where u.DepartmentId= d.Id;

Page 10: Query Analyser , SQL Server Groups, Transact –SQL

Tools Menu Items

The Tools menu contains three groupings, one for the Object Browser and Object Search, one for managing statistics and indexes, and one for setting options and customizing

Page 11: Query Analyser , SQL Server Groups, Transact –SQL

Object Browser

SQL Query Analyzer also has an "Object Browser" that you can use to browse and edit tables, views, and stored procedures. The Object Browser also displays a list of common SQL Server functions and their parameters.

To open the Object Browser, press F8. Alternatively, you can click the Object Browser icon   on the toolbar. Another way of showing the Object Browser is to goTools > Object Browser > Show/hide. The Object Browser displays to the left of your workspace.

Page 12: Query Analyser , SQL Server Groups, Transact –SQL

Object Browser

Page 13: Query Analyser , SQL Server Groups, Transact –SQL

Writing QueriesYou are now ready to write SQL queries against your database. You can use this interface to create database objects (such as databases, tables, views etc), insert data into a database table, select data, update data, delete data.

Page 14: Query Analyser , SQL Server Groups, Transact –SQL

The Edit Menu Items

The Edit menu items contain the usual commands for cutting, copying, pasting, finding, and replacing text strings. The Undo command will undo typing, one letter at a time. All actions have keyboard shortcut keys assigned,

which are displayed in the right column of the menu list.

Page 15: Query Analyser , SQL Server Groups, Transact –SQL

Templates

The Edit|Insert Template command displays a list of built-in templates that ship with SQL Server 2000

Page 16: Query Analyser , SQL Server Groups, Transact –SQL

Double-click the category you’re interested in to display a list of individual templates.

Page 17: Query Analyser , SQL Server Groups, Transact –SQL

Click Open when you’ve selected the desired template. This displays the template file in the SQL pane of the Query Analyzer.

Page 18: Query Analyser , SQL Server Groups, Transact –SQL

SQL Server Groups

You use SQL Server groups to organize sets of computers running SQL Server. You can organize these groups by, say, function or department. You can even create subgroups within a group. In SQL Server Management Studio, you use the Registered Servers view to work with server groups. The top-level groups are already created for you, based on the SQL Server instances.

Page 19: Query Analyser , SQL Server Groups, Transact –SQL

Registering SQL Server Group

1.On the File menu, click New SQL Server Registration.

The Register SQL Server wizard is displayed.

.

Page 20: Query Analyser , SQL Server Groups, Transact –SQL

2.Click Next

Page 21: Query Analyser , SQL Server Groups, Transact –SQL

3.In Available servers, type or select the name of the SQL Server instance that you want to register, then click Add.

If you want to remove a SQL Server instance from the list, in Added servers, select the name of the instance and click Remove.

4. When you have added all the instances that you want to register to the Added servers list, click Next.

Page 22: Query Analyser , SQL Server Groups, Transact –SQL

5.Select the authentication method, and for SQL Server authentication enter the Login name and Password.

For SQL Server authentication, you can select the Prompt for the SQL Server account information when connecting check box. If you select this option, SQL Backup will not connect to the SQL Server automatically; you will have to connect manually by right-clicking on the SQL Server instance in the servers pane, and clicking Connect. A dialog box will then be displayed for you enter the authentication details.

Page 23: Query Analyser , SQL Server Groups, Transact –SQL

6. Select the group to which you want to add the server.

Click Next.

Page 24: Query Analyser , SQL Server Groups, Transact –SQL

9. SQL Backup registers the SQL Server instances. This may take a few minutes.

To check the authentication details for a SQL Server, click the SQL Server instance and then click Properties. You can then enter the details and test them. Note that to change the details for registration, you must re-enter the details in the authentication page of the wizard.

Click Finish.

Page 25: Query Analyser , SQL Server Groups, Transact –SQL

T-SQL

Transact-SQL is central to the use of Microsoft SQL Server. All applications that communicate with SQL Server do so by sending Transact-SQL statements to the server, regardless of an application's user interface.

Page 26: Query Analyser , SQL Server Groups, Transact –SQL

Cursor

A cursor is a pointer to a set of records returned by a SQL statement. It enables you to take a set of records and deal with it on a row-by-row basis.

Page 27: Query Analyser , SQL Server Groups, Transact –SQL

Defining and Using Cursors

Step 1: Declare cursor:

To use a cursor you need to first declare it. This provides definitions and characteristics of the record set for which the cursor will be used.

Declare cursorname Cursor

Read_Only

For SQL statement

Ex: Declare ACustomer Cursor

Read_Only

For select * from customer where rating=‘a’

Page 28: Query Analyser , SQL Server Groups, Transact –SQL

Step 2: Open cursor:

After declaring, cursor must be opened before it can be used in your procedure or batch code.

OPEN cursorname

Example: Open Acustomer

Page 29: Query Analyser , SQL Server Groups, Transact –SQL

Step 3: Fetch data into variables:

This command is used to extract the data from the cursor.

FETCH Next From cursorname into list of local variables

Example: Fetch Next ACustomer into @CustID, @CustName, @CustCity, @CustRating

Use @@Fetch_Status to test if record exist. If @@Fetch_Status = 0, fetching is successful

Page 30: Query Analyser , SQL Server Groups, Transact –SQL

Step 4: CLOSE cursorname

The CLOSE command is used to free the current result set and locks.

Step 5: Deallocate cursor

DEALLOCATE command is used to remove the cursor reference.

deallocate Acustomer

Page 31: Query Analyser , SQL Server Groups, Transact –SQL

THANKYOU