SQL and T-SQL

To use T-SQL statements we need some way of sending these statements to the RDBMS. One way is to use the OSQL command line utility. If you are a DBA who has worked with SQL Server 6.5, you will notice that the OSQL command line utility has replaced the older ISQL utility which does not support some of the new features of SQL Server 2000. While supporting SQL Server 2000, OSQL uses the command line interface and is therefore not very user friendly. However, if you would like to learn more about this utility lookup “osql utility” in the SQL Server Books Online.

The tool we are going to use throughout this series to write, edit, and optimize our T-SQL scripts is called the SQL Query Analyzer. This graphical user interface tool lets you run T-SQL statements, create scripts that can be saved and edited, and it will even provide information that can be used to optimize both databases and T-SQL statements.

There are two main ways to open the SQL Query Analyzer. First, you can open it directly by selecting “Query Analyzer” from the Microsoft SQL Server group on the Start Menu. When the SQL Query Analyzer opens, the first thing you will be asked is to select a server and provide the log on credentials. The following screen shows a connection to the local installation of SQL Server using Windows authentication.

Alternatively, you can access the Query Analyzer from inside the Enterprise Manager. Let’s look at how to do this by creating a new database using T-SQL and the Query Analyzer. To start, open Enterprise Manager and connect to your SQL Server by selecting it in the tree pain.

Next, on the tools menu select Query Analyzer. The first thing you will notice is that we are not asked to select a server or for login information. When you start Query Analyzer from within the Enterprise Manager, Query Analyzer automatically uses the server you have selected in the tree pain. Additionally, it passes the logon credentials that you used to connect to the server in Enterprise Manager.

The status bar at the bottom of the Query window gives us important information about the server we are connected to, the user we are connected as, the database we are using, as well as other status information.