If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Please help; MySQL can't create table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-25-10, 03:12
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Please help; MySQL can't create table

Hello there people, I'm sorry if this is a noob question.

I've recently installed Xampp 1.7.3a (on Ubuntu 10.04 64bit) and configured it. Everything was fine, I even went into MySQL root to set the privileges for other user.

After that, I re-logged in with the other user and created a database which was fine BUT when I tried to create table within it, I can't seem to do it so.
Following is my query statement and for the life of me, I can't figure out what's wrong with it
Quote:
CREATE TABLE 'hits' ('id' int, 'song' varchar(255), 'artist' varchar(255), 'year' (int), 'genre' varchar(255));
The error I get is
Quote:
#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 ''hits' ('id' int, 'song' varchar(255), 'artist' varchar(255), 'year' (int), 'gen' at line 1
It's really doing my head in and I don't know how to sort it out.
I mean in Oracle, this query statement would've worked!

So, please help me out.
I would greatly appreciate it.

Thank you very much.

Regards,
db_newbie
Reply With Quote
  #2 (permalink)  
Old 12-25-10, 06:32
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Quote:
Originally Posted by db_newbie View Post
I mean in Oracle, this query statement would've worked!
absolutely not, no, it wouldn't've

this is invalid --
Code:
CREATE TABLE 'hits' ...

this is valid (but not in oracle) --
Code:
CREATE TABLE `hits` ...

this is valid (in all databases) --
Code:
CREATE TABLE hits ...

you can't use a string as a table or column name

and the error message tells you ~exactly~ where the problem is, doesn't it


__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 12-25-10, 06:37
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by r937 View Post
absolutely not, no, it wouldn't've

you can't use a string as a table or column name

and the error message tells you ~exactly~ where the problem is, doesn't it


Oh, I see. I keep thinking I have to use single quotes in MySQL but in actual fact, they're not single quotes! It's a symbol beside number 1, right?

Well, thank you very much, sir. I've just tried it and it worked

Cheers and regards.
Reply With Quote
  #4 (permalink)  
Old 12-25-10, 06:49
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
they're called backticks, and no, you don't have to use them, and you shouldn't

best practise is not to name your tables or columns with a name that requires escaping, like if the name contains a special character or blank, or the name is a reserved word

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 12-27-10, 09:40
db_newbie db_newbie is offline
Registered User
 
Join Date: Nov 2010
Posts: 30
Quote:
Originally Posted by r937 View Post
they're called backticks, and no, you don't have to use them, and you shouldn't

best practise is not to name your tables or columns with a name that requires escaping, like if the name contains a special character or blank, or the name is a reserved word

Yes, that totally makes sense.

Next time, I'll work out what the error msg is saying before letting out my frustration

Again, thank you.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On