SQLServer 中获取特定表的所有列名+类型的几种方法

方法一: 取得表里所有列名称

Select Name FROM SysColumns Where id=Object_Id('表名')

​​​​​​​方法二: 取得有关数据库对象(sysobjects 表中列出的任何对象)

 sp_help 表名

也可直接  sp_help 获取所有表

方法三:取得库内所有表的名称+字段类型

 Select * From INFORMATION_SCHEMA.COLUMNS 

方法四:取某个表的所有字段

declare @objid int,@objname char(40)
set @objname = '表名'
select @objid = id from sysobjects where id = object_id(@objname)
select  'Column_name'  = name from syscolumns where id = @objid order by colid

方法五: 获取特定表的所有列名和备注信息

SELECT
  a.column_id AS No,
  a.name AS 列名,
  isnull(g.[value],'-') AS 说明
FROM
  sys.columns a left join sys.extended_properties g
 on (a.object_id = g.major_id AND g.minor_id = a.column_id)
WHERE
  object_id =
    (SELECT object_id FROM sys.tables WHERE name = '表名')

你可能感兴趣的:(SQL,Sever,sqlserver,数据库,sql)