I'm just wondering if there is a short SQL query that works in the same way as pandas df.info() function does in Python? Something that quickly returns the table metadata.
CodePudding user response:
The below should work:
select schema_name(tab.schema_id) as schema_name,
tab.name as table_name,
col.column_id,
col.name as column_name,
t.name as data_type,
col.max_length,
col.precision
from sys.tables as tab
inner join sys.columns as col
on tab.object_id = col.object_id
left join sys.types as t
on col.user_type_id = t.user_type_id
order by schema_name,
table_name,
column_id;
CodePudding user response:
if you want to extract details form sql server then information_schema objects will help
select * from information_schema.tables t
join information_schema.columns c on t.table_name = c.table_name
where t.table_name = '<your table name>'
