欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

获取数据库中用户表所有列和列的数据类型

程序员文章站 2022-03-12 15:00:01
获取数据库中,所有用户表中每一列名和其数据类型。 SELECT OBJECT_NAME(c.OBJECT_ID) AS [Table_Name], c.[name] AS [Column_Name] ,t.[name] AS [Data_Type_Name] FROM sys.columns AS ......

获取数据库中,所有用户表中每一列名和其数据类型。

 

select object_name(c.object_id) as [table_name], c.[name] as [column_name] ,t.[name] as [data_type_name]  
from sys.columns as c  
left join sysobjects as s on (c.[object_id] = s.[id])  
left join sys.types as t on (c.[user_type_id]=t.[user_type_id])
where s.xtype = 'u'