I’m making a web based mail system, and I have to create a table with this code:
CREATE TABLE 'messages'( 'ID' INT(250) NOT NULL AUTO_INCREMENT, 'To' VARCHAR(250) NOT NULL, 'CC' VARCHAR(250), 'BCC' VARCHAR(250), 'From' VARCHAR(250) NOT NULL, 'Subject' VARCHAR(250), 'Message' LONG BLOB NOT NULL, 'Date' DATETIME NOT NULL, 'MailboxID' INT(250) NOT NULL, Primary Key ('ID'));
MySQL says:
#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 ''messages'( 'ID' INT(250) NOT NULL AUTO_INCREMENT, 'To' VARCHAR(250) NOT NULL,' at line 1
Might be the error is in DATETIME
?
Advertisement
Answer
Get rid of the quotes around your column identifiers. Either use ticks or nothing at at all:
CREATE TABLE messages( ID INT(250) NOT NULL AUTO_INCREMENT, To VARCHAR(250) NOT NULL, CC VARCHAR(250), BCC VARCHAR(250), From VARCHAR(250) NOT NULL, Subject VARCHAR(250), Message LONG BLOB NOT NULL, Date DATETIME NOT NULL, MailboxID INT(250) NOT NULL, Primary Key (ID));
Or:
CREATE TABLE `messages`( `ID` INT(250) NOT NULL AUTO_INCREMENT, `To` VARCHAR(250) NOT NULL, `CC` VARCHAR(250), `BCC` VARCHAR(250), `From` VARCHAR(250) NOT NULL, `Subject` VARCHAR(250), `Message` LONG BLOB NOT NULL, `Date` DATETIME NOT NULL, `MailboxID` INT(250) NOT NULL, Primary Key (`ID`));