Skip to content

Instantly share code, notes, and snippets.

@wbhinton
Created December 3, 2019 16:35
Show Gist options
  • Save wbhinton/64fe9324d87563c4b7aa47b147ff6fdd to your computer and use it in GitHub Desktop.
Save wbhinton/64fe9324d87563c4b7aa47b147ff6fdd to your computer and use it in GitHub Desktop.
Get the schema for an existing DB.
SELECT OBJECT_SCHEMA_NAME(c.object_id) SchemaName
,o.Name AS Table_Name
,c.Name AS Field_Name
,t.Name AS Data_Type
,t.max_length AS Length_Size
,t.precision AS Precision
FROM sys.columns c
INNER JOIN sys.objects o ON o.object_id = c.object_id
LEFT JOIN sys.types t ON t.user_type_id = c.user_type_id
WHERE o.type = 'U'
-- and o.Name = 'YourTableName'
ORDER BY o.Name
,c.Name
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment