1.6K
This article will walk you through a T-SQL script that can be used to retrieve comprehensive information on table columns, including schema, name, data type, length, precision, scale, and more. Whether you’re a beginner or an experienced DBA, this script will help you quickly and easily access the information you need to manage your databases effectively.
T-Sql
---------------------------------------------------------------------------------
-- Script to get the table column attribute details
---------------------------------------------------------------------------------
USE [dbname here] -- replace "dbname here" with your database name
GO
SELECT
OBJECT_SCHEMA_NAME(T.[object_id], DB_ID()) AS [Schema]
, T.[name] AS [table_name]
, AC.[name] AS [column_name]
, TY.[name] AS system_data_type
, AC.[max_length]
, AC.[precision]
, AC.[scale]
, AC.[is_nullable]
, AC.[is_ansi_padded]
FROM
sys.[tables] AS T
INNER JOIN sys.[all_columns] AC
ON T.[object_id] = AC.[object_id]
INNER JOIN sys.[types] TY
ON AC.[system_type_id] = TY.[system_type_id] AND AC.[user_type_id] = TY.[user_type_id]
WHERE
T.[is_ms_shipped] = 0
ORDER BY
T.[name], AC.[column_id]
Note
For further information on this post, kindly refer to the original source provided in the link below.
Source: mssqltips
