Results 1 to 5 of 5
  1. #1
    Join Date
    Feb 2008
    Posts
    2

    Unanswered: Creating table using query

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

    Code:
    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)
    );
    When I try putting that in phpmyadmin SQL query box, it returns:

    #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
    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.

  2. #2
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    my guess would be there is no column defined for 'parent_pid'.

    as most computers are thick as two short planks you have to expressly tell it what you want. If you let computers decide for ourselves, according to Hollywood you will either get HAL like psychosis, or Terminator style aggression to mankind amongst other minor issues.

    like most compilers or interpreters its reporting the start of where MySQL lost the plot,,, it was expecting a column list in brackets eg
    KEY `parent_pid` (parent_pid),

  3. #3
    Join Date
    Feb 2008
    Posts
    2
    Quote Originally Posted by healdem
    my guess would be there is no column defined for 'parent_pid'.

    as most computers are thick as two short planks you have to expressly tell it what you want. If you let computers decide for ourselves, according to Hollywood you will either get HAL like psychosis, or Terminator style aggression to mankind amongst other minor issues.

    like most compilers or interpreters its reporting the start of where MySQL lost the plot,,, it was expecting a column list in brackets eg
    KEY `parent_pid` (parent_pid),
    Ourselves? You must be one of those new generation high tech machines that can read and write

    Sorry, but as I am not very acquanted with databases and such could you tell me exactly where to put that line you suggested?

    Thanks for you help!

  4. #4
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    replace this line --

    KEY `parent_pid` ,

    with this one --

    KEY `parent_pid` (parent_pid),

    then look carefully at the difference between them, and try to understand what healdem meant when he said "there is no column defined for 'parent_pid'"

    you will need to make a similar change to the following line

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  5. #5
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    follow your table definition
    you have defined the columns for key domain using column domain
    Code:
    KEY `domain` (`domain`),
    so do the same with parent_pid and expires
    http://dev.mysql.com/doc/refman/5.0/...ate-table.html

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •