views:

80

answers:

2
CREATE TABLE `pastebin` (
      `pid` int(11) NOT NULL auto_increment,
      `poster` varchar(16) default NULL,
      `posted` datetime default NULL,
      `code` text,
      `parent_pid` int(11) default '0',
      `format` varchar(16) default NULL,
      `codefmt` mediumtext,
      `codecss` text,
      `domain` varchar(255) default '',
      `expires` DATETIME,
      `expiry_flag` ENUM('d','m', 'f') NOT NULL DEFAULT 'm',

      PRIMARY KEY  (`pid`),
      KEY `domain` (`domain`),
      KEY `parent_pid`,
      KEY `expires`
    );

After creating a database and copy-pasting the SQL query into PHPMyAdmin I get the following error:

#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 '
  KEY `expires`
)' at line 16
+1  A: 

You have to specify the columns that you want to have indexed in parenthesis after the name of the index.

At the bottom of your definition:

  PRIMARY KEY  (`pid`),
  KEY `domain` (`domain`),
  KEY `parent_pid`,
  KEY `expires`

Would become:

  PRIMARY KEY  (`pid`),
  KEY `domain` (`domain`),
  KEY `parent_pid` (`parent_pid`),
  KEY `expires` (`expires`)
TheJacobTaylor
Thanks, that seemed to work. I really need to learn MySQL...
PHLAK
+1  A: 
CREATE TABLE `pastebin` (
      `pid` int(11) NOT NULL auto_increment,
      `poster` varchar(16) default NULL,
      `posted` datetime default NULL,
      `code` text,
      `parent_pid` int(11) default '0',
      `format` varchar(16) default NULL,
      `codefmt` mediumtext,
      `codecss` text,
      `domain` varchar(255) default '',
      `expires` DATETIME,
      `expiry_flag` ENUM('d','m', 'f') NOT NULL DEFAULT 'm',

      PRIMARY KEY  (`pid`),
      KEY `domain` (`domain`),
      KEY `parent_pid` (`parent_pid`),
      KEY `expires` (`expires`)
    );

Indexes need names, as they are entities in the DB.

Itay Moav