简体   繁体   English

在SQL Server中别名列名称

[英]Aliasing column names in SQL server

Is there a way in SQL server to alias column names for a particular table and store the aliases somewhere such that you can access the aliases while querying? SQL Server中是否可以为特定表的列名添加别名,并将别名存储在某个位置,以便您可以在查询时访问别名? I have a table where I cannot change column names and I am trying to figure out if there is a way to alias them to make them more user friendly. 我有一个表,在该表中我无法更改列名,并且我试图找出是否可以使用别名来使它们更加用户友好。

CREATE VIEW vw_RenameTable
AS
Begin

   Select GoodName1 = DumbName1
          ,GoodName2 = DumbName2
   From MyTable

End

A view would be the natural answer to the question. 一个观点将是对这个问题的自然回答。 But, if you want to access the columns in the same table, you can use computed columns: 但是,如果要访问同一表中的列,则可以使用计算列:

alter table mytable add bettercolumn as [Bad Ugly Name];

You can then use the computed column in a select on the same table . 然后,您可以在同一表的选择中使用计算列。

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

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