SQL Server 查询以获取表中所有列的数据类型? [英] SQL Server query to get data type for all columns in table?
本文介绍了SQL Server 查询以获取表中所有列的数据类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 SSMS 中运行了这个 SQL Server 2012 查询:
I have this SQL Server 2012 query that I am running in SSMS:
SELECT name, max_length, precision, scale, is_nullable
FROM sys.columns
WHERE object_id = OBJECT_ID('dbo.testtable')
它正在返回我想要的东西:
It is returning what I want:
但是,我想在此查询中添加列的数据类型,使其看起来像我在对象资源管理器中看到的那样.关于如何添加数据类型的任何想法?
However, I would like to add the data type of the column in this query, so that it looks like what I see in the object explorer. Any thoughts on how to add the data type?
推荐答案
SELECT c.name,
c.max_length,
c.precision,
c.scale,
c.is_nullable,
t.name
FROM sys.columns c
JOIN sys.types t
ON c.user_type_id = t.user_type_id
WHERE c.object_id = Object_id('dbo.testtable')
这篇关于SQL Server 查询以获取表中所有列的数据类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文