Thursday, December 31, 2015

SQL Script to retrieve metadata of a Sql Statement and/or Table of SQL Server

This script will help us to retrieve metadata/column information from a SQL Statement and/or a Table. Download this script, RETRIVE_METADATA_SCRIPT.sql.

This script will provide the below information .. 

  1. TABLE_OWNER
  2. ORDINAL_POSITION
  3. COLUMN_NAME
  4. TYPE_NAME
  5. LENGTH
  6. PRECISION
  7. IS_NULLABLE
See the below table to understand parameters …

Parameter Name
Type
IN/OUT
Description
@SQLStm
VARCHAR(MAX)
INPUT
Put fully qualified table name, i.e. [dbo].[TEST], luckily you can use DB name with table name, i.e. [TEST_DB].[dbo].[TEST].
OR you can pass a SQL statement to check duplicate output, i.e. "select * from [dbo].[TEST]"
@isTable
BIT
INPUT
Mention @SQLStm contains a Table name or SQL stm. TRUE for table and FALSE for SQL Stm.

No comments:

Post a Comment