表的字段(列)名称 [英] field (column) names of tables
本文介绍了表的字段(列)名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要说一张桌子,例如tab1它具有5列.即col1,col2,.....,col5.
当我们检索数据时,我们总是获取表中的内容.但我想得到
表字段/列的名称(此处为"col1,col2,...")及其内容.我该怎么做?实际上我有20个这样的表,因此手动进行比较困难.因此,我需要一些自动化脚本或自动化功能.
I am having a table say for e.g. tab1 it has 5 cols. namely col1,col2,.....,col5.
When we retrive data, we always fetch the content inside the table. But i want to get
name of the table field/column (here "col1,col2,...") alongwith its content. How can i do it? Actually i am having 20 such tables so doing it manually is difficult. So i need some automated script or an automated function.
推荐答案
您可以使用类似的方法从数据库中的所有表和列中获取数据. >
You can use something like this to get data from all the tables and columns within a database.
DECLARE @SQL AS NVARCHAR(MAX)
SET @SQL = ''
SELECT @SQL = @SQL + 'SELECT * FROM ' + TABLE_SCHEMA + '.' + TABLE_NAME + CHAR(13)
FROM INFORMATION_SCHEMA.TABLES
EXEC (@SQL)
这篇关于表的字段(列)名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文