Solved

error when creating table

Posted on 2004-10-15
6
260 Views
Last Modified: 2011-04-14
Hi,
I encounter an error when creating tables with PRIMARY KEY. The error is as fallows:
"Data base created succesfulyYou have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY (movie_id), KEY movie_type (movie_type,movie_year) ) TYPE"
My current mysql version is 4.0.21
Any Ideas?
Thank's
M
0
Comment
Question by:margotsk
  • 3
  • 2
6 Comments
 
LVL 12

Expert Comment

by:minichicken
ID: 12326774
Hi

What are you using to creat your table? PHPMyAdmin or some kind?
If you would like to create a table with PRIMARY key, it need to have syntax like this.....

CREATE TABLE `movie` (
`movie_id` INT NOT NULL AUTO_INCREMENT ,
`movie_type` VARCHAR( 100 ) NOT NULL ,
PRIMARY KEY ( `movie_id` )
);

Hope this help...
0
 
LVL 1

Expert Comment

by:NeonDevil
ID: 12331314
It may be easier to install and use a mySQL utility, I would suggest either mySQL Control Center (http://dev.mysql.com/downloads/other/mysqlcc.html) or mySQL Query Browser (http://dev.mysql.com/downloads/query-browser/index.hml)

Also, double check your syntax for your CREATE TABLE command:
http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html
0
 

Author Comment

by:margotsk
ID: 12386927
Thank's for responding,
The code is as follows:
$movie="CREATE TABLE movie (
movie_id INT(11) NOT NULL AUTO_INCREMENT,
movie_name VARCHAR(255) NOT NULL,
movie_type TINYINT(2) NOT NULL DEFAULT 0,
movie_year INT(4) NOT NULL DEFAULT 0,
movie_leadactor INT(11) NOT NULL DEFAULT 0,
movie_director INT(11) NOT NULL DEFAULT 0,
PRIMERY KEY (movie_id),
KEY movie_type (movie_type,movie_year)
) TYPE=MyISAM AUTO_INCREMENT=4 ";

I am learing MySQL from book "Beginning PHP,Apache,MySQL Web development" and I am at beging of chapter that covers MySQL topic. Through google in another forum i found some one else using the same book and having exaclty the same problem in the same code. She never posted, how she did solve it. That make's me thing that there is some typo or syntex mistake which i, as begginer, do not see. It is certanly some thing to do with line [KEY movie_type....] I went trought the manual that NeonDevil listed, but everything seems correct.
Thank's
m
0
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
LVL 12

Accepted Solution

by:
minichicken earned 500 total points
ID: 12387433
Hi

I found the error, there is a typo with the word PRIMERY >> it should be PRIMARY, it works fine, i test it...

Here is the correct syntax:

CREATE TABLE movie(
movie_id INT( 11 ) NOT NULL AUTO_INCREMENT ,
movie_name VARCHAR( 255 ) NOT NULL ,
movie_type TINYINT( 2 ) NOT NULL DEFAULT 0,
movie_year INT( 4 ) NOT NULL DEFAULT 0,
movie_leadactor INT( 11 ) NOT NULL DEFAULT 0,
movie_director INT( 11 ) NOT NULL DEFAULT 0,
PRIMARY KEY ( movie_id ) ,
KEY movie_type( movie_type, movie_year )
) TYPE = MYISAM AUTO_INCREMENT =4


regards-
0
 

Author Comment

by:margotsk
ID: 12391178
Thank's a lot...and also thank you for making me look so silly..ha, ha
All points are yours
All the Best,
m
0
 
LVL 12

Expert Comment

by:minichicken
ID: 12391789
no prob :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Creating and Managing Databases with phpMyAdmin in cPanel.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now