|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Yesterday @ 7:11 AM
Points: 877,
Visits: 1,159
|
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 6:46 AM
Points: 5,102,
Visits: 20,207
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 1:51 AM
Points: 1,972,
Visits: 1,821
|
|
Very bad worded question:
Query text during caching in SQL 2005 This is related to SQL Server caching. What should be the output of following T-SQL query:
USE AdventureWorks2008R2 GO EXEC uspPrintError GO SELECT st.text QueryText FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE text LIKE N'%uspPrintError%'; In the title, it refers to sql2005, than it uses AdventureWorks2008R2 In sql2005, I get an error: "plan_handle" is not a recognized table hints option. I also tried to run
SELECT text FROM sys.dm_exec_sql_text(0x0500FF7F79BB1808C8808A04000000000000000000000000) But it returns this: -- uspPrintError prints error information about the error that caused -- execution to jump to the CATCH block of a TRY...CATCH construct. -- Should be executed from within the scope of a CATCH block otherwise -- it will return without printing any error information. CREATE PROCEDURE [dbo].[uspPrintError] AS BEGIN SET NOCOUNT ON;
-- Print error information. PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + ', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) + ', State ' + CONVERT(varchar(5), ERROR_STATE()) + ', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') + ', Line ' + CONVERT(varchar(5), ERROR_LINE()); PRINT ERROR_MESSAGE(); END; At end I answered BOTH: EXEC ... and text for the stored proc. The explanation seems to be approximate!
|
|
|
|
|
SSCertifiable
       
Group: General Forum Members
Last Login: Today @ 9:28 AM
Points: 5,243,
Visits: 7,054
|
|
Good question. I answered wrong; I thought all statements were cached.
Hardik, do you have any references where I can read more about this?
Hugo Kornelis, SQL Server MVP Visit my SQL Server blog: http://sqlblog.com/blogs/hugo_kornelis
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Yesterday @ 7:11 AM
Points: 877,
Visits: 1,159
|
|
Carlo Romagnano (11/14/2010)
Very bad worded question: Query text during caching in SQL 2005 This is related to SQL Server caching. What should be the output of following T-SQL query: USE AdventureWorks2008R2 GO EXEC uspPrintError GO SELECT st.text QueryText FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE text LIKE N'%uspPrintError%'; In the title, it refers to sql2005, than it uses AdventureWorks 2008R2In sql2005, I get an error: "plan_handle" is not a recognized table hints option.I also tried to run SELECT text FROM sys.dm_exec_sql_text(0x0500FF7F79BB1808C8808A04000000000000000000000000) But it returns this: -- uspPrintError prints error information about the error that caused -- execution to jump to the CATCH block of a TRY...CATCH construct. -- Should be executed from within the scope of a CATCH block otherwise -- it will return without printing any error information. CREATE PROCEDURE [dbo].[uspPrintError] AS BEGIN SET NOCOUNT ON;
-- Print error information. PRINT 'Error ' + CONVERT(varchar(50), ERROR_NUMBER()) + ', Severity ' + CONVERT(varchar(5), ERROR_SEVERITY()) + ', State ' + CONVERT(varchar(5), ERROR_STATE()) + ', Procedure ' + ISNULL(ERROR_PROCEDURE(), '-') + ', Line ' + CONVERT(varchar(5), ERROR_LINE()); PRINT ERROR_MESSAGE(); END;At end I answered BOTH: EXEC ... and text for the stored proc. The explanation seems to be approximate! Thanks Carlo for pointing out the typo mistake on header (title). This behavior is same for SQL Server 2005 & in SQL 2008 and I used AdventureWorks2008R2 database so has idea that it is SQL2k8 R2 database provided by Microsoft.
Also, thanks for the validation of explanation provided.
Thanks
|
|
|
|
|
SSCrazy Eights
        
Group: General Forum Members
Last Login: Today @ 6:39 AM
Points: 9,376,
Visits: 6,472
|
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Today @ 1:02 AM
Points: 1,277,
Visits: 1,609
|
|
|
|
|
|
SSCommitted
      
Group: General Forum Members
Last Login: Yesterday @ 1:51 AM
Points: 1,972,
Visits: 1,821
|
|
Execute the batch without the 'GO'
EXEC uspLogError SELECT st.text QueryText,objtype FROM sys.dm_exec_cached_plans CROSS APPLY sys.dm_exec_sql_text(plan_handle) AS st WHERE text LIKE N'%uspLogError%' Result: CREATE PROCEDURE [dbo].[uspLogError] ....,'Proc' EXEC uspLogError SELECT st.text QueryText FROM sys.dm_exec_cached_plans ....,'Adhoc'
The body of the stored procedure is cached in the objtype = 'Proc' (see also other info about the proc). the second record is the plan stored with objtype = 'Adhoc'
See also: http://msdn.microsoft.com/en-us/library/ms187404.aspx
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Thursday, January 24, 2013 9:59 PM
Points: 1,354,
Visits: 1,299
|
|
| Any BOL links you can provide regarding this? There wasn't one in the explanation.
|
|
|
|
|
SSC Eights!
      
Group: General Forum Members
Last Login: Monday, May 20, 2013 3:35 AM
Points: 969,
Visits: 650
|
|
|
|
|