|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Tuesday, May 21, 2013 10:53 AM
Points: 1,662,
Visits: 1,709
|
|
vk-kirov (3/1/2010)
Oleg Netchaev (3/1/2010) there are a couple of records inserted into the system tables when the procedure is created. The procedure name is inserted into sysobjects and the text of the stored procedure is inserted into syscomments.Syscomments and sysobjects are not system tables anymore (in MSSQL 2005 and higher). They are views included for backward compatibility only (BOL: http://msdn.microsoft.com/en-us/library/ms177596.aspx, http://msdn.microsoft.com/en-us/library/ms186293.aspx). The 'sys.syscomments' view is quite complicated, and it queries data from several system tables. Beware of using those views in new projects, use sys.objects and sys.sql_modules instead  Sorry, this is my bad, I forgot to mention that this is only applicable to the SQL Server 2000. I understand that the situation in 2005/2008 is different. The actual data is stored in the base system table named sys.sysschobjs. The direct access to this table is not available except through DAC, and therefore, the object related data is instead exposed through the system views like the ones you mention. The bottom line is the same: there are records inserted into the system tables the moment the proc is created. So, to access the text of the proc via sys.objects one can use something like this:
select [object_id], object_name([object_id]) [object_name], object_definition([object_id]) definition from sys.objects where [object_id] = object_id('[your_schema].[your_proc_name]'); and via sys.sql_modules like this:
select [object_id], object_name([object_id]) [object_name], definition from sys.sql_modules where [object_id] = object_id('[your_schema].[your_proc_name]'); Oleg
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Sunday, May 19, 2013 7:02 PM
Points: 2,861,
Visits: 405
|
|
I choose the right answer "False" but that's because of this statement:
Stored procedures are optimized at creation Because I believe that stored procedures are only optimized when they are first run, not when they are created  Now I also learn that it's not stored on disk. Thanks, good question!
Urbis, an urban transformation company
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Friday, May 17, 2013 2:53 AM
Points: 1,530,
Visits: 359
|
|
| thanks for the question :). learned something new today
|
|
|
|
|
Forum Newbie
      
Group: General Forum Members
Last Login: Thursday, March 04, 2010 1:03 AM
Points: 2,
Visits: 8
|
|
Actually, you can persist query plans to disk.
MS SQL allows you to export a query plan to an XML file. You can then alter the query plan as required because contrary to MS documentation, the query optimiser does NOT work out anywhere close to the best execution when multiple view each with many joins are involved.
You can then force the query to execute using your customised plan.
So technically, you can persist a query plan. it's probably not what the question actually meant which was does the query optimiser save plans by default, in which case the answer in no. But you can force a query plan to be used which has been saved to disk.
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 6:52 AM
Points: 2,018,
Visits: 2,852
|
|
| Thanks all for your explanations. It cleared it up for me.
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Yesterday @ 12:25 PM
Points: 7,110,
Visits: 7,184
|
|
Nice question but one niggle about the explanation: if the procedure option RECOMPILE is specified the same plan will NOT be used in subsequent executions. This can be useful if an SP's plan would be heavily influenced by one of its parameters or if some of the tables it accesses changed very rapidly (so that statistics are very different) compared to the frequency with which the proc is called.
Tom Is minic a gheibheann béal oscailte dorn dúnta. Is minig a cheapas beul fosgailte dòrn dùinte.
|
|
|
|
|
Mr or Mrs. 500
      
Group: General Forum Members
Last Login: Friday, March 15, 2013 10:35 AM
Points: 594,
Visits: 654
|
|
Thanks for an easy one, I usually need to think alot more. Actually, I was surprised to see how many missed that one. I will be careful to cover that topic a little more carefully in class...
Now to go find another question that I can get wrong... :)
Peter Trast Microsoft Certified ...(insert many literal strings here) Microsoft Design Architect with Alexander Open Systems
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 1:03 AM
Points: 10,990,
Visits: 10,543
|
|
|
|
|