I am new to MySQL and am messing with a database I created just to learn.
I created my first table and it worked OK:
mysql> CREATE TABLE Pizzas(ItemID INTEGER PRIMARY KEY, Size INTEGER, Price DECIMAL);
Query OK, 0 rows affected (0.90 sec)
then I tried to create another table using CONSTRAINT (I was simply copying the way foreign keys were created in a class I am taking) and I got an error:
mysql> CREATE TABLE Customers(CustomerID PRIMARY KEY, Name CHAR(20), ItemID INTEGER, CONSTRAINT FOREIGN KEY (ItemID) REFERENCES Pizzas (ItemID));
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 'PRIMARY KEY, Name CHAR(20), ItemID INTEGER, CONSTRAINT FOREIGN KEY (ItemID) REFE' at line 1
I'm using a linux computer and my MySQL version is 5.5. Why am I getting this problem?
INTEGER) forCustomerID. Also, some advice: useVARCHAR(20)instead ofCHAR(20)for theNamecolumn, asCHAR(20)will be padded with spaces at the end. You won't see them, but they'll be there and they'll mess you up.