简体   繁体   English

在临时表中插入另一个表的名称SQL Server 2008

[英]Insert in a temporal table the names of another table SQL Server 2008

Is there a way to have something like: 有没有办法像这样:

id NameColumn 
--------------
1  sex
2  age 
3  weight
4  height

...from a known table: ...根据已知表格:

sex age weight height....
--------------------------
m   12    200  200
f   22    100  150
...

This is because I have like 300 fields so I would like to maker a map table. 这是因为我喜欢300个字段,所以我想创建一个映射表。

Say you have a known table 假设您有一张已知的桌子

create table known (sex char(1), age int, weight int, height int)

This gives you the output required 这为您提供所需的输出

select
    [id] = ORDINAL_POSITION,
    [NameColumn] = COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'known'

Output: 输出:

id          NameColumn
----------- -----------
1           sex
2           age
3           weight
4           height

If you wanted to create a table out of it, something like 如果您想从中创建表,例如

select
    [id] = ORDINAL_POSITION,
    [NameColumn] = COLUMN_NAME
into #temporal
from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME = 'known'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM