SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


EXECUTE


EXECUTE

Author
Message
Raghavendra Mudugal
Raghavendra Mudugal
SSCertifiable
SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)SSCertifiable (5.5K reputation)

Group: General Forum Members
Points: 5546 Visits: 2958
Thanks for the question, Simply Nice :-)

(we have like 250+ database on each principals where the structure of each database is same, only the data stored is different, hosted on multiple database server over different regions. I once wrote a query to fetch a specific set of records from one server on all databases and I used this "execute use db1" and the execute the underlying sql statement and then store them in the table variable.. the whole query was awful and then I changed in to one whole batch and then stored it in to the temp table and used the cursor to loop trough the next database and then execute it and then store in result... the complete execution took only 15 seconds to fetch records from all database..like some less than 600 records... I actually came to now here that executing of the "use" statement using "execute" does not changes the physical connection of the current session. memory recall :-) )

ww; Raghu
--
The first and the hardest SQL statement I have wrote- "select * from customers" - and I was happy and felt smart.
Tom Thomson
Tom Thomson
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50846 Visits: 13159
Toreador (2/15/2013)
How long until the first complaint that the correct answer is None of the Above, because there's no such database as AdventureWorks2008 ;-)

Surely no one will be quite that silly?

I just assumed that the idea was to assume it was run against SQL Server 2008 with that DB installed, since it's clear from the question and the answer options that one has to assume the database exists and that seems most likely to happen with an SQLS 2008 installation.

Of course the database name would have to change to AdventureWorks2008R2 for those statements to work on my laptop, but who cares - it's not as if I would actually want to run that code anyway!

Tom

venkat9.sql
venkat9.sql
Old Hand
Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)Old Hand (344 reputation)

Group: General Forum Members
Points: 344 Visits: 260
an easy one to start my day...and its a friday!!!!!!!!!! :-D

___________________________________________________________________
If I can answer a question then anyone can answer it..trying to reverse the logic.. Hehe
EL Jerry
EL Jerry
SSCertifiable
SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)SSCertifiable (5.1K reputation)

Group: General Forum Members
Points: 5109 Visits: 1346
Great question to end the week. Thank you, Lokesh.

"El" Jerry.

"A watt of Ottawa" - Gerardo Galvan

To better understand your help request, please follow these best practices.
Lynn Pettis
Lynn Pettis
SSC Guru
SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)SSC Guru (224K reputation)

Group: General Forum Members
Points: 224860 Visits: 40420
I think this is not quite correct:



Database context will not be changed while executing EXECUTE statements. The reason is changes in database context last only until the end of the EXECUTE statement.



Really should be more like:

The database context will only be changed within the context of the EXECUTE statement. It will have no effect on the context in which the EXECUTE statement is run.

Other than that, very good back to basics question. Surprised by the number of people that have missed the question so far.

Cool
Lynn Pettis

For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here or when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here and here
Managing Transaction Logs

SQL Musings from the Desert Fountain Valley SQL (My Mirror Blog)
mtassin
mtassin
SSChampion
SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)SSChampion (13K reputation)

Group: General Forum Members
Points: 13306 Visits: 72528
Stewart "Arturius" Campbell (2/14/2013)
Good back-to-basics question, thanks Lokesh


+1. Had to think for a second about it... which is about all I have in thinking power today anyway. Smile



--Mark Tassin
MCITP - SQL Server DBA
Proud member of the Anti-RBAR alliance.
For help with Performance click this link
For tips on how to post your problems
Rich Mechaber
Rich Mechaber
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5759 Visits: 3691
Good question, had to think a bit.

Stupid me, scratching my head: what is that extra "databasename#" argument doing there?

I always use the (unnecessary) "As" when aliasing columns, b/c otherwise I..... scratch my head reading code. :-D

Rich
(Bob Brown)
(Bob Brown)
Ten Centuries
Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)Ten Centuries (1.4K reputation)

Group: General Forum Members
Points: 1419 Visits: 1145
Great question to end the week and go into a three-day weekend. Thanks.
SQLRNNR
SQLRNNR
SSC Guru
SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)SSC Guru (144K reputation)

Group: General Forum Members
Points: 144971 Visits: 18651
Thanks for the question

Jason...AKA CirqueDeSQLeil
_______________________________________________
I have given a name to my pain...MCM SQL Server, MVP
SQL RNNR
Posting Performance Based Questions - Gail Shaw
Learn Extended Events

Iulian -207023
Iulian -207023
SSCarpal Tunnel
SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)SSCarpal Tunnel (4.4K reputation)

Group: General Forum Members
Points: 4361 Visits: 1248
Thanks for that

Iulian
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum








































































































































































SQLServerCentral


Search