0

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
2
  • You do that in a query, not in the table. flowerName is a really good name for the column. Commented Oct 19, 2017 at 17:51
  • thank you, but how? Commented Oct 19, 2017 at 17:56

3 Answers 3

3

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
Sign up to request clarification or add additional context in comments.

3 Comments

thank you, but when I do a "select * from flowers", the name changes back to flowerName in the result pane, I want it to always say "The name of the flower is"
@Hanna You can't alias *; each column must be aliased individually.
Since you want it to always be that way, you have two options that @zorkolot showed in his answer.
0

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.

If you want to do it in SQL, it would be something like:
SELECT flowerName as 'The Name of the flower is' FROM flowers

Comments

0

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

1 Comment

The view would be the right option in my opinion. Column names looking like that are a bootable offense.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.