Creating table using query

Discussion in 'MySQL' started by pkallberg21, Feb 26, 2008.

  1. #1
    Hello, I am trying to create a table in my database using a query, but it is not working. Here is the query:

    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`
    	);
    
    create table recent
    (
    	domain varchar(255),
    	pid int not null,
    	seq_no int not null,
    	
    	primary key(domain,seq_no)
    );
    Code (markup):

    When I try putting that in phpmyadmin SQL query box, it returns:

    What am I doing wrong? If I am not able to do this through phpmyadmin, how would I go about doing this using a .php file? I have tried doing this many times using guides, with no luck, so I would appreciate it if someone could help me.
     
    pkallberg21, Feb 26, 2008 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    I think the error is here: `domain` varchar(255) default '',

    Try default null;
     
    jestep, Feb 27, 2008 IP
  3. bluegrass special

    bluegrass special Peon

    Messages:
    790
    Likes Received:
    50
    Best Answers:
    0
    Trophy Points:
    0
    #3
    There are two potential issues. One, I don't know if MySQL allows datetime as a key field. Two, key fields should never allow null values. You did not set a default value for expires.
     
    bluegrass special, Feb 29, 2008 IP
  4. SoKickIt

    SoKickIt Active Member

    Messages:
    305
    Likes Received:
    30
    Best Answers:
    0
    Trophy Points:
    70
    #4
    KEY `parent_pid`,
    KEY `expires`
    Code (markup):
    ...should be:

    KEY (`parent_pid`),
    KEY (`expires`)
    Code (markup):
    Everything else is fine.
     
    SoKickIt, Feb 29, 2008 IP
  5. mrmclz

    mrmclz Peon

    Messages:
    82
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Did you get it to work?
     
    mrmclz, Feb 29, 2008 IP
  6. pkallberg21

    pkallberg21 Peon

    Messages:
    295
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Yes, SoKickIt had the right solution :)

    Thanks mate!
     
    pkallberg21, Mar 1, 2008 IP