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 > Creating table using query

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-27-08, 08:03
pkallberg21 pkallberg21 is offline
Registered User
 
Join Date: Feb 2008
Posts: 2
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:

Quote:
#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.
Reply With Quote
  #2 (permalink)  
Old 02-27-08, 10:02
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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),
Reply With Quote
  #3 (permalink)  
Old 02-27-08, 12:31
pkallberg21 pkallberg21 is offline
Registered User
 
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!
Reply With Quote
  #4 (permalink)  
Old 02-27-08, 12:49
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
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

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-27-08, 12:50
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,262
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
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