Created
May 11, 2016 15:28
-
-
Save pilotgeraldb/862e2c5747e0d7dc558c05ebd62c216b to your computer and use it in GitHub Desktop.
retrieves table information in mssql
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE @tablename varchar(50) | |
SET @tablename = '' -- <--EDIT THIS VALUE | |
DECLARE @columnname varchar(50) | |
SET @columnname = '' -- <--EDIT THIS VALUE | |
SELECT | |
SCHEMANAME = SCHEMA_NAME(SYSTABLES.SCHEMA_ID), | |
TABLENAME = SYSTABLES.NAME, | |
COLUMNNAME = _SYSCOLUMNS.NAME, | |
DataType = (SELECT TOP 1 NAME FROM SYS.TYPES _SYSTYPES WHERE _SYSCOLUMNS.system_type_id = _SYSTYPES.system_type_id), | |
DataLen = _SYSCOLUMNS.max_length | |
FROM SYS.TABLES SYSTABLES | |
JOIN SYS.COLUMNS _SYSCOLUMNS ON SYSTABLES.OBJECT_ID = _SYSCOLUMNS.OBJECT_ID | |
WHERE SYSTABLES.NAME = @tablename AND _SYSCOLUMNS.NAME LIKE @columnname |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment