SELECT src.TABLE_SCHEMA,src.TABLE_NAME,src.COLUMN_NAME,src.ORDINAL_POSITION,
CASE WHEN DATA_TYPE IN('nvarchar','varchar') THEN src.DATA_TYPE+'<'+CAST(src.LengthOfDataType AS NVARCHAR(20))+'>'
ELSE src.DATA_TYPE END AS DataType
FROM
(
SELECT cols.TABLE_SCHEMA,cols.TABLE_NAME,cols.COLUMN_NAME,cols.DATA_TYPE,cols.ORDINAL_POSITION,
CASE WHEN cols.CHARACTER_MAXIMUM_LENGTH IS NULL THEN '' ELSE cols.CHARACTER_MAXIMUM_LENGTH END AS LengthOfDataType
FROM INFORMATION_SCHEMA.COLUMNS AS cols
JOIN INFORMATION_SCHEMA.tables AS tabs
ON cols.TABLE_NAME = tabs.TABLE_NAME AND cols.TABLE_SCHEMA=tabs.TABLE_SCHEMA
AND tabs.TABLE_TYPE='base table'
)src
CASE WHEN DATA_TYPE IN('nvarchar','varchar') THEN src.DATA_TYPE+'<'+CAST(src.LengthOfDataType AS NVARCHAR(20))+'>'
ELSE src.DATA_TYPE END AS DataType
FROM
(
SELECT cols.TABLE_SCHEMA,cols.TABLE_NAME,cols.COLUMN_NAME,cols.DATA_TYPE,cols.ORDINAL_POSITION,
CASE WHEN cols.CHARACTER_MAXIMUM_LENGTH IS NULL THEN '' ELSE cols.CHARACTER_MAXIMUM_LENGTH END AS LengthOfDataType
FROM INFORMATION_SCHEMA.COLUMNS AS cols
JOIN INFORMATION_SCHEMA.tables AS tabs
ON cols.TABLE_NAME = tabs.TABLE_NAME AND cols.TABLE_SCHEMA=tabs.TABLE_SCHEMA
AND tabs.TABLE_TYPE='base table'
)src
No comments:
Post a Comment