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

时间:2017-10-19 17:46:38

标签: sql sql-server database database-design

我想为我的表添加一个列名

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

而不是结果:

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

我希望结果是:

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

3 个答案:

答案 0 :(得分:3)

看起来你要做的只是列的别名。这可以通过以下方式轻松处理:

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

答案 1 :(得分:0)

您无法在创建表时执行此操作,但您可以在SQL中选择,或使用您用于连接的语言在输出中更改它。

如果你想在SQL中这样做,它将是这样的:
SELECT flowerName as 'The Name of the flower is' FROM flowers

答案 2 :(得分:0)

这应该是它。

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

如果要更改表名:

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

或者,如果您喜欢冒险(并且不想更改原始表格结构),您可以查看:

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

然后你可以:SELECT * FROM vwFlowers