Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Created March 10, 2026 10:47
Show Gist options
  • Select an option

  • Save MarkPryceMaherMSFT/32f9e21deb2f784bbb47b2d50f71d412 to your computer and use it in GitHub Desktop.

Select an option

Save MarkPryceMaherMSFT/32f9e21deb2f784bbb47b2d50f71d412 to your computer and use it in GitHub Desktop.
query to get the datatypes for each column
SELECT
s.name AS SchemaName,
t.name AS TableName,
c.name AS ColumnName,
ty.name AS DataType,
c.max_length,
c.precision,
c.scale,
c.is_nullable
FROM sys.tables t
JOIN sys.schemas s ON t.schema_id = s.schema_id
JOIN sys.columns c ON t.object_id = c.object_id
JOIN sys.types ty ON c.user_type_id = ty.user_type_id
ORDER BY
s.name,
t.name,
c.column_id;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment