List:General Discussion« Previous MessageNext Message »
From:Michael Stassen Date:October 26 2005 3:33am
Subject:Re: Problem with syntax 4 creating 1 table
View as plain text  
Ed wrote:
> Shawn green was very kindly helping me ouy trying to make mysql tables 
> and I thought I had got the hang of it until I get this error-any ideas? 
> Thanks a lot
> 
> CREATE TABLE PurchasedProducts(
> `int_saleCart` INT AUTO_INCREMENT NOT NULL ,
> `int_ClientID` INT,
> `int_ProductID` INT,
> `int_Quantity` INT,
> `int_saleCart` PRIMARY KEY ( int_saleCart )
> ) ENGINE = MYISAM
> 
> MySQL said: Documentation
> 
> |#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 'PRIMARY KEY ( int_saleCart )
> ) ENGINE = MYISAM' at line 6 |
> || 
> |Here is what I'm trying to make:|
> | |
> |PurchasedProducts:
> int_saleCart int IDENTITY
> int_ClientID int
> int_ProductID int
> int_Quantity int|

As the error message is telling you, you have the wrong syntax.  The correct 
syntax is described in the manual 
<http://dev.mysql.com/doc/refman/5.0/en/create-table.html>.

In short, you define a name with

   col_name COLUMN_TYPE optional_extras

but you define an index with

   INDEX_TYPE optional_index_name (column or columns to be indexed).

Your last line starts with a name, like a column defintion, but then tries to 
define an index (PRIMARY KEY).  Instead, you need

   CREATE TABLE PurchasedProducts(
   `int_saleCart` INT AUTO_INCREMENT NOT NULL,
   `int_ClientID` INT,
   `int_ProductID` INT,
   `int_Quantity` INT,
   PRIMARY KEY (int_saleCart)
   ) ENGINE = MYISAM

or simply

   CREATE TABLE PurchasedProducts(
   `int_saleCart` INT AUTO_INCREMENT NOT NULL PRIMARY KEY,
   `int_ClientID` INT,
   `int_ProductID` INT,
   `int_Quantity` INT
   ) ENGINE = MYISAM

Michael
Thread
Problem with syntax 4 creating 1 tableEd26 Oct
  • Re: Problem with syntax 4 creating 1 tableMichael Stassen26 Oct
  • Re: Problem with syntax 4 creating 1 tableRhino26 Oct
    • Re: Problem with syntax 4 creating 1 tableMichael Stassen26 Oct