简体   繁体   English

将列名称添加到SQL Server中的现有表

[英]Adding column name to existing table in SQL Server

I want to add a column name for my table 我想为表格添加列名

create table flowers
(
     flowerName varchar (22) not null, primary key
)

Instead of the result being: 而不是结果是:

flowerName
----------
tulip

I want the result to be: 我希望结果是:

The Name of the flower is:
--------------------------
tulip

It looks like all you want to do is alias the column. 您似乎要做的就是为该列添加别名。 This is easily handled by the following: 可以通过以下方式轻松处理:

select flowerName AS [The Name of the flower is:] from flowers

You can't do that on table creation, but you can do it on select in SQL, or change it in output in the language that you're using to connect. 您不能在创建表时执行此操作,但是可以在SQL中的select上执行此操作,也可以使用用于连接的语言在输出中更改它。

If you want to do it in SQL, it would be something like: 如果要在SQL中执行此操作,将类似于:
SELECT flowerName as 'The Name of the flower is' FROM flowers

This should be it. 应该是这样。

create table flowers
(
     [The Name of the flower is:] varchar (22) not null primary key
)

If you want to alter the table name: 如果要更改表名:

ALTER TABLE flowers
RENAME COLUMN "flowerName" TO "The Name of the flower is:"

Alternatively if you're adventurous (and don't want to change the original table structure) you can make a view: 另外,如果您喜欢冒险(不想更改原始表结构),则可以进行查看:

CREATE VIEW vwFlowers AS
SELECT flowerName AS [The Name of the flower is:]
  FROM flowers

Then you can: SELECT * FROM vwFlowers 然后,您可以: SELECT * FROM vwFlowers

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

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