SQL Server 根据表名查询包含的列名、类型、长度等

发布时间 2023-08-29 11:13:36作者: 摸头长不高

 

 

select	c.name as '列名',
		case when c.is_identity = 1 then '√' else '×' end as '自增',
		ty.name as '数据类型',
		c.max_length as '长度',
		case when c.is_nullable=1 then '√' else '×' end as '允许null',
		isnull(e.value,'') as '说名'
		from sys.tables as t 
join sys.all_columns as c on t.object_id=c.object_id
left join sys.extended_properties as e on e.major_id=c.object_id and e.minor_id=c.column_id
join sys.types as ty on ty.user_type_id=c.user_type_id
where t.name='calss' and SCHEMA_NAME(t.schema_id)='school'