610
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.
---------------------------------------------------------------------------------
-- 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]
As a data professional, I am passionate about constantly striving to expand my knowledge and skills in the field while sharing my expertise with fellow enthusiasts through howsdata. My philosophy is simple: "one step at a time." It's all about progress, no matter how slow, so long as we do not stop.
Howsdata ©2024 · All lefts reserved