2017-10-19 69 views
0

我要爲我的表中添加列名在SQL Server中添加列名現有表

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

相反的結果是的:

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

我想要得到的結果是:

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

你做一個查詢,而不是在表中。 'flowerName'是這個專欄的一個非常好的名字。 –

+0

謝謝,但如何? – Hanna

回答

3

它看起來像所有你想要做的是別名的列。這是很容易處理如下:

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

謝謝,但是當我做一個「從花中選擇*」時,名稱在結果窗格中變回到flowerName,我希望它總是說「花的名字是」 – Hanna

+0

@Hanna你不能別名* ;每列必須單獨別名。 – UnhandledExcepSean

+0

既然你想永遠那樣,你有兩個選擇@zorkolot在他的答案中顯示。 – UnhandledExcepSean

0

你不能這樣做,在創建表,但你可以做到這一點就選擇在SQL,或者您正在使用連接的語言改變它在輸出。

如果你想這樣做的SQL,這將是這樣的:
SELECT flowerName as 'The Name of the flower is' FROM flowers

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

+0

在我看來,這種觀點是正確的選擇。看起來像這樣的列名是可引導的進攻。 – UnhandledExcepSean