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 > Does mySQL supports varchar as Primary key?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-25-04, 06:13
InHeaven InHeaven is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Smile Does mySQL supports varchar as Primary key?

I had been facing problems in creating mysql using foreign key.
The problems falls on the userID foreign in Combination. They prompt me error (Error 1064: You have an error in your sql syntex. Check the manual that corresponds to your mySQL server version for the right syntex use near 'User(userID) ON UPDATE CASCADE ON DELETE CASCADE) TYPE=INNODB'). This problem does not occur when i create other tables. Thus it should not be syntex error. I would appretiate if somebody could help me to solved it. Thank alot. =)
=========================================
CREATE TABLE User
(
userID VARCHAR(255) NOT NULL,
firstName VARCHAR(255),
lastName VARCHAR(255),
shipAdd TEXT,
userStatus VARCHAR(255),
pswd VARCHAR(8),
dateJoined INT,
PRIMARY KEY(userID)) TYPE=INNODB;

CREATE TABLE Combination
(
coID INT NOT NULL AUTO_INCREMENT,
itemID INT NOT NULL,
userID VARCHAR(255),
PRIMARY KEY(coID),
INDEX(itemID),
INDEX(userID),
FOREIGN KEY(itemID) REFERENCES Items(itemID) ON UPDATE CASCADE ON DELETE CASCADE,
FOREIGN KEY(userID) REFERENCES User(userID) ON UPDATE CASCADE ON DELETE CASCADE) TYPE=INNODB;
=========================================
Reply With Quote
  #2 (permalink)  
Old 01-25-04, 06:55
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
i have never created innodb tables

your syntax looks okay

quite possibly USER is a reserved word

i would rename that table, or else always refer to it in backticks, e.g.

... FOREIGN KEY(userID) REFERENCES `User`(userID)
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 01-25-04, 07:10
InHeaven InHeaven is offline
Registered User
 
Join Date: Jan 2004
Posts: 4
Smile

Quote:
Originally posted by r937
i have never created innodb tables

your syntax looks okay

quite possibly USER is a reserved word

i would rename that table, or else always refer to it in backticks, e.g.

... FOREIGN KEY(userID) REFERENCES `User`(userID)
==============================================

Oh i got it! Thanx alot! I had been solving this question for the past three hours. Thanx!
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