Saturday 11 April 2015

SP_DESCRIBE_FIRST_RESULT_SET to view result set metadata

      When I was looking for what’s new in the SQL server 2012, one small and interesting item I found that SET FMTONLY and sp_describe_first_result_set, let’s have a look:

SET FMTONLY: This setting has two values ON and OFF, when it is ON client only can see the format of the result set, not data. This is for run time setting, not compile time. Below is the example: 

SET FMTONLY OFF
GO 
SELECT * 
  FROM [AdventureWorks2008R2].[HumanResources].[Employee]






SET FMTONLY ON
GO 
/****** Script for SelectTopNRows command from SSMS  ******/
SELECT * 
  FROM [AdventureWorks2008R2].[HumanResources].[Employee]


SP_DESCRIBE_FIRST_RESULT_SET: This procedure is more advance and useful than FMTONLY. This procedure returns the metadata information of the first possible result set, with complete detail. This procedure takes statement as dynamic query. You can pass multiple query at once. This will return the meta-Data information of the first possible result set. Below is the example:

 EXEC sp_describe_first_result_set
 @tsql = N'select * from [AdventureWorks2008R2].[Sales].[vSalesPersonSalesByFiscalYears];'














1 comment:

  1. Could you show handling an error from this? Sure you can get results when it is good. But how to handle an error.

    ReplyDelete

Data Mesh

  Data Mesh is a relatively new approach to managing and organizing data within organizations, especially large enterprises. It advocates fo...