Transact-SQL is best
learned by experience. The view from the trenches is usually better than the
one from the tower.
Choosing a SQL
Editor
The first step on
the road to Transact-SQL fluency is to pick a SQL entry and editing tool.
You'll use this
facility to enter
SQL commands, execute them, and view their results.
The Query Analyzer
tool that's included with SQL Server is a respectable SQL entry facility. Those
familiar with previous versions of SQL Server will remember this tool as
ISQL/W. The new version resembles its predecessor in many ways but sports a
slightly more modern interface.
a mere SQL entry
facility. In addition to basic query entry and execution facilities, it
provides a wealth of analysis and tuning info
The first order of
business when you start Query Analyzer is to connect to the server, so make
sure your server is running. Enter your username and password when prompted (if
your server is newly installed, username sa defaults to an empty
password) and select your server name. If Query Analyzer and SQL Server are
running on the same machine, you can use"." (a period—with no quotes)
or (local) (don't forget the parentheses) for the server name. The user
interface of the tool is self-explanatory: You key T-SQL queries into the top
pane of the window and view results in the bottom one.
The databases
currently defined on your server are displayed in a combo-box on each window's
toolbar. You can select one from the list to make it the active database for
the queries you run in that window. Pressing Ctrl-E, F5, or Alt-X runs your
query, while Ctrl-F5 checks it for syntax errors.
TIP
Hot Tip If you
execute a query while a selection is active in the edit window, Query Analyzer
will
execute the
selection rather than the entire query. This is handy for executing queries in
steps and
for quickly
executing another command without opening a new window.
One of the features
sorely missed in Query Analyzer is the Alt-F1 object help facility. In ISQL/W,
you could select an object name in the edit window and press Alt-F1 to get help
on it. For tables and views, this presented an abbreviated sp_help report. It
was quite handy and saved many a trip to a new query window merely to list an
object's columns.
If you're a
command-line devotee, you may prefer the OSQL utility to Query Analyzer. OSQL
is an ODBCbased command-line utility that ships with SQL Server. Like Query
Analyzer, OSQL can be used to enter Transact-SQL statements and stored
procedures to execute. Once you've entered a query, hit return to drop to a new
line, then type GO and hit return again to run it (GO must be leftmost on the
line).
TSQL Tutorials...
No comments:
Post a Comment