469,331 Members | 4,734 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,331 developers. It's quick & easy.

query plan in clear text

hi.
coming from postgresql, i am used to textual references to most of the
things i do with the database. i feel a little lost with all the graphical.

i have few questions regarding MS SQL 2000
1. what is the best (or easiest) way of getting a table definition in text?
it could be either a CREATE TABLE sql-query or a just a definition,
something like:
TABLE thisTable
id integer
value varchar(10)
etc. etc.
2a. how do i get a query plan and how do i get it in text.
2b. are there planner modes that show more or less of what actually
happened, verbose mode perhaps?
2c. if i ask for a query plan, will SQL server actually run the query or
will it only produce a plan. if the query is run, does it commit or
rollback by default?
stig
Dec 11 '05 #1
7 2039
Hi

I assume you have found books online that will give you a great deal of
information regarding language/tools etc... the latest version can be
downloaded from
http://www.microsoft.com/downloads/d...DisplayLang=en

This will give you information on sp_help (and similar procedures) which
will give information regarding an object.

Scripting can be done from Enterprise Manager, the General SQL option will
create a script to create the object which can be written to a file or
pasted into another window. This can usually be found by right clicking the
item in the tree view.

There are also scripting options in Query Analyser if you display the object
browser. This gives you multiple options regarding how you want to script it
and where output should go. This is also usually a right click option.

John
You can look at sp_help
"stig" <_n*****************@yahoo.se> wrote in message
news:dn**********@oden.abc.se...
hi.
coming from postgresql, i am used to textual references to most of the
things i do with the database. i feel a little lost with all the
graphical.

i have few questions regarding MS SQL 2000
1. what is the best (or easiest) way of getting a table definition in
text?
it could be either a CREATE TABLE sql-query or a just a definition,
something like:
TABLE thisTable
id integer
value varchar(10)
etc. etc.
2a. how do i get a query plan and how do i get it in text.
2b. are there planner modes that show more or less of what actually
happened, verbose mode perhaps?
2c. if i ask for a query plan, will SQL server actually run the query or
will it only produce a plan. if the query is run, does it commit or
rollback by default?
stig

Dec 11 '05 #2
On Sun, 11 Dec 2005 20:31:37 +0100, stig wrote:
hi.
coming from postgresql, i am used to textual references to most of the
things i do with the database. i feel a little lost with all the graphical.
Hi Stig,

Answers inline.

i have few questions regarding MS SQL 2000
1. what is the best (or easiest) way of getting a table definition in text?
it could be either a CREATE TABLE sql-query or a just a definition,
something like:
TABLE thisTable
id integer
value varchar(10)
etc. etc.
John Bell already addressed this question.

2a. how do i get a query plan and how do i get it in text.
To get an execution plan in text, add
SET SHOWPLAN_TEXT ON
go
before your query.
When using Query Analyzer, you can also use either Query | Current
connection properties (for one connection) or Tools | Options |
Connection properties (to change the defaults) and add a tick before the
"Set showplan_text" option.
2b. are there planner modes that show more or less of what actually
happened, verbose mode perhaps?
I personally prefer the graphical version offered by Query Analyzer over
the text version offered by SET SHOWPLAN_TEXT ON, but both carry
essentially the same information.
2c. if i ask for a query plan, will SQL server actually run the query or
will it only produce a plan. if the query is run, does it commit or
rollback by default?


In QA, you can use Query | Display Estimated Execution Plan (Ctrl-L) to
get an estimate of the query plan without running the query, or you can
get the real execution plan, including statistics on actually processed
numbers of rows, by running the query with the option Query | Show
Execution Plan (Ctrl-K) turned on - this will actually run the query.

If you use the SET SHOWPLAN_TEXT ON option, the query will actualy be
run, unless you also activate the fmtonly option with the commands
SET FMTONLY ON
go
Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Dec 11 '05 #3
On Sun, 11 Dec 2005 20:31:37 +0100, stig wrote:

(snip)
if the query is run, does it commit or
rollback by default?


Hi Stig,

Sorry - clicked "Send" before answering the last question.

If the query is run, it will commit by default, unless:

a) you explicitly execute a BEGIN TRANSACTION command before it (in that
case, the transaction remains open until you explicitly ROLLBACK or
COMMIT it or until the connection is lost),

b) you have activated the inplicit_transactions option, in which case
SQL Server will act as there is a BEGIN TRANSACTION command even if you
didn't add it yourself, or

c) it aborts due to an error (in that case, it gets rolled back).

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Dec 11 '05 #4
stig (_n*****************@yahoo.se) writes:
coming from postgresql, i am used to textual references to most of the
things i do with the database. i feel a little lost with all the
graphical.


Here are some good news: you don't have to use it. Use Query Analyzer
for all your tasks, and leave Enterprise Manager to rot in a corner.

Personally, I do almost all tasks from Query Analyzer, and about the only
graphical thing there is the query plan. The only thing I do from
Enterprise Manager is to deal with jobs.


--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 11 '05 #5
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
If you use the SET SHOWPLAN_TEXT ON option, the query will actualy be
run, unless you also activate the fmtonly option with the commands


No, SET SHOWPLAN_TEXT (and SHOWPLAN_ALL) ON turns off execution:

SET SHOWPLAN_TEXT ON
go
PRINT 'Showplan is ON'
go
SET SHOWPLAN_TEXT OFF
go
PRINT 'Showplan is OFF'
go

The command to use if you want plans and also execute, is
SET STATISTICS PROFILE ON.
--
Erland Sommarskog, SQL Server MVP, es****@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Dec 11 '05 #6
On Sun, 11 Dec 2005 21:28:01 +0000 (UTC), Erland Sommarskog wrote:
Hugo Kornelis (hugo@pe_NO_rFact.in_SPAM_fo) writes:
If you use the SET SHOWPLAN_TEXT ON option, the query will actualy be
run, unless you also activate the fmtonly option with the commands


No, SET SHOWPLAN_TEXT (and SHOWPLAN_ALL) ON turns off execution:

SET SHOWPLAN_TEXT ON
go
PRINT 'Showplan is ON'
go
SET SHOWPLAN_TEXT OFF
go
PRINT 'Showplan is OFF'
go

The command to use if you want plans and also execute, is
SET STATISTICS PROFILE ON.


Hi Erland,

You're right. Thanks for putting me straight.

I guess it's time to write another 1000 lines of "never post without
testing" :-(

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Dec 12 '05 #7

"Hugo Kornelis" <hugo@pe_NO_rFact.in_SPAM_fo> wrote in message
news:ke********************************@4ax.com...
I guess it's time to write another 1000 lines of "never post without testing" :-(


No, you just have to create a query that does so.

Please post DDL and all statements. :-)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)

Dec 13 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Eugenio | last post: by
2 posts views Thread by Keith C. Perry | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.