Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
|
02-10-2010, 03:50 PM
|
#1
|
Member
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567
Rep:
|
MySQL Syntax Error
Hey guys,
I am reading Sams Teach Yourself SQL in one hour a day. In this book they work with both Oracle and MySQL to teach you SQL. So I installed mysql on my box and I am creating the empty database they use in this book so I can follow along as I read. I have noticed a few typos in the book and now I have noticed some code errors too. I just don't know enough to fix em. I am working on creating the empty database and I am getting syntax errors when I create certain tables. I have checked both the printed version of the book and the electronic version (which differ slightly) and both give me the same synatax errors.
First is Creating the first table of the database. Here is the code given to me to enter.
The Electronic version
Quote:
create table checks
(‘ check’ integer not null,
payee varchar(20) not null,
amount decimal(6, 2) not null,
remarks varchar(20) not null) ;
|
The Printed Version
Quote:
create table checks
('check' integer not null,
payee varchar(20) not null,
amount decimal(6, 2) not null,
remarks varchar(20) not null);
|
In both cases I receive the following error
Code:
mysql> create table checks
-> ('check' integer not null,
-> payee varchar(20) not null,
-> amount decimal(6,2) not null,
-> remarks varchar(20) not null);
ERROR 1064 (42000): 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 ''check' integer not null,
payee varchar(20) not null,
amount decimal(6,2) not n' at line 2
In addition to that I also have another table giving me a similar synatax error.
Quote:
create table convert
(name varchar(1 5) not null,
testnum numeric(9) not null) ;
|
Any ideas how I can correct this error and create these tables?
|
|
|
02-10-2010, 05:08 PM
|
#2
|
Senior Member
Registered: Aug 2009
Posts: 3,790
|
I don't do sql too often but I'll give it a shot -
- I don't think the single quotes are supposed to be there in the first one
- the second one has a gap between the two digits - '(1 5)' try removing it
You may be able to prevent future issues by downloading errata from the book website.. I haven't checked to see if this book has one but most do.
<edit>You may find it helpful to check the reference manual - http://dev.mysql.com/doc/index.html</edit>
cheers
Last edited by kbp; 02-10-2010 at 05:10 PM.
|
|
|
02-10-2010, 05:37 PM
|
#3
|
Member
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567
Original Poster
Rep:
|
Code:
mysql> create table checks (check integer not null, payee varchar(20) not null, amount decimal(6,2) not null, remarks varchar(20) not null);
ERROR 1064 (42000): 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 'integer not null, payee varchar(20) not null, amount decimal(6,2) not null, rema' at line 1
mysql> create table convert
-> (name varchar(15) not null,
-> testnum numeric(9) not null);
ERROR 1064 (42000): 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 'convert
(name varchar(15) not null,
testnum numeric(9) not null)' at line 1
mysql>
I believe check is a mysql command thus the need for single quotes. Also if I remove the gap in the second problem I still have an issue. I just don't get it.
|
|
|
02-10-2010, 06:04 PM
|
#4
|
LQ Newbie
Registered: Nov 2009
Distribution: Slackware / Arch
Posts: 10
Rep:
|
I believe if the field name is going to be the same name as a MySQL command it needs to be encapsulated in backticks `` not single quotes ''.
|
|
|
02-10-2010, 11:12 PM
|
#6
|
Member
Registered: Oct 2004
Location: Atlanta
Distribution: CentOS, RHEL, HP-UX, OS X
Posts: 567
Original Poster
Rep:
|
Quote:
Originally Posted by Weird0ne
I believe if the field name is going to be the same name as a MySQL command it needs to be encapsulated in backticks `` not single quotes ''.
|
That is exactly what the problem was. Thanks. I would have never figured that out because I am still learning.
|
|
|
All times are GMT -5. The time now is 08:46 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|