Skip to content

Instantly share code, notes, and snippets.

@MarshalOfficial
Created October 5, 2020 10:52
Show Gist options
  • Select an option

  • Save MarshalOfficial/b2c8753e87b29ee6f2a7a3f4dc26e438 to your computer and use it in GitHub Desktop.

Select an option

Save MarshalOfficial/b2c8753e87b29ee6f2a7a3f4dc26e438 to your computer and use it in GitHub Desktop.
get all tables column information with datatype name
SELECT s.name AS 'schema', ts.name AS TableName,
c.name AS column_name, c.column_id,
SCHEMA_NAME(t.schema_id) AS DatatypeSchema,
t.name AS Datatypename
,t.is_user_defined, t.is_assembly_type
,c.is_nullable, c.max_length, c.PRECISION,
c.scale
FROM sys.columns AS c
INNER JOIN sys.types AS t ON c.user_type_id=t.user_type_id
INNER JOIN sys.tables ts ON ts.OBJECT_ID = c.OBJECT_ID
INNER JOIN sys.schemas s ON s.schema_id = ts.schema_id
--where t.name like '%text%' or t.name like '%image%'
ORDER BY s.name, ts.name, c.column_id
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment