Dmitry Makovetskiyd
Dmitry Makovetskiyd

Reputation: 7053

Alterning a table that has spaces in its name

I want to add 3 columns. There are two things that I dont know, one is how to specify a default value for each column, and then next is how to alter a table that has got spaces:

    ALTER TABLE  app name and url
ADD COLUMN price VARCHAR(200)
ADD COLUMN type_of_membership VARCHAR(200)
ADD COLUMN special_deal VARCHAR(200)

I get this error:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'name and url ADD COLUMN price VARCHAR(200) ADD COLUMN type_of_membership VARCH' at line 1

I guess it is because I have a tables name with spaces.

Is this how you insert default values:

    ALTER TABLE  app name and url
ADD COLUMN price VARCHAR(200) DEFAULT 'None'
ADD COLUMN type_of_membership VARCHAR(200) DEFAULT 'None'
ADD COLUMN special_deal VARCHAR(200) DEFAULT 'None'

UPDATE This is what I executed:

ALTER TABLE  `app name and url`
ADD COLUMN price VARCHAR(200) DEFAULT 'None',
ADD COLUMN type_of_membership VARCHAR(200) DEFAULT 'None',
ADD COLUMN special_deal VARCHAR(200) DEFAULT 'None';

and this is what I got:

 'mydb.app name and url' is not BASE TABLE

The error is because it is a view..I get it now. I will have to modify the view

Upvotes: 1

Views: 2049

Answers (2)

Joe G Joseph
Joe G Joseph

Reputation: 24046

Use ``

You have to replace the table name with

 ALTER TABLE  `app name and url`


SQL Fiddle demo

Upvotes: 2

John Woo
John Woo

Reputation: 263693

In Mysql, you need to escape it using backtick (grave accent)

ALTER TABLE  `app name and url`
ADD COLUMN price VARCHAR(200)
ADD COLUMN type_of_membership VARCHAR(200)
ADD COLUMN special_deal VARCHAR(200)

What is the meaning of grave accent (AKA backtick) quoted characters in MySQL?

PS: Next time use only alphanumeric in your table and column name.

Upvotes: 3

Related Questions