从表中获取列数 [英] Get the number of columns from table

查看:102
本文介绍了从表中获取列数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我必须从表中查找列数,并从该表中查找每列的名称.
请帮助我,如何找到它?
谢谢.

Hi,

I have to find number of column from table and name of each column from that table.
please help me,how to find it?
Thanks.

推荐答案

这是查找表中的列数的方法.
This is to find the number of columns in a table.
SELECT COUNT(*) AS num_of_columns
FROM INFORMATION_SCHEMA.COLUMNS a
WHERE a.TABLE_NAME = 'tablename'


这是要获取表中的所有列.


This is to get all the columns in a table.

SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS a
WHERE a.TABLE_NAME = 'tablename'


尝试以下SQL:
Try this SQL:
EXEC SP_Columns myTable

它将返回一个表格,其中每一列都位于单独的行中.这将为您提供所需的所有信息!

It will return a table with each column in a separate row. This gives you all the info you need!


此查询将为您完成:
This query will do it for you:
SELECT * FROM sys.columns WHERE object_id = OBJECT_ID('dbo.Table1')


这篇关于从表中获取列数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆