Log in

View Full Version : Creating an sql table error



keyboard
08-11-2011, 07:27 AM
CREATE TABLE `messages` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NULL
`message` TEXT NOT NULL ,
`from` INT( 11 ) NOT NULL ,
`to` INT( 11 ) NOT NULL ,
`from_viewed` BOOL NOT NULL DEFAULT '0',
`to_viewed` BOOL NOT NULL DEFAULT '0',
`from_deleted` BOOL NOT NULL DEFAULT '0',
`to_deleted` BOOL NOT NULL DEFAULT '0',
`from_vdate` DATETIME NULL ,
`to_vdate` DATETIME NULL ,
`from_ddate` DATETIME NULL ,
`to_ddate` DATETIME NULL ,
`created` DATETIME NOT NULL
) ENGINE = MYISAM ;


This code is causing an error. Any help

djr33
08-11-2011, 11:34 AM
Why not tell us what the error is?

JShor
08-11-2011, 05:41 PM
I already spotted the error myself. It's a syntax error, you forgot a comma after '`message` TEXT NOT NULL '.

This should work:


CREATE TABLE `messages` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NULL ,
`message` TEXT NOT NULL ,
`from` INT( 11 ) NOT NULL ,
`to` INT( 11 ) NOT NULL ,
`from_viewed` BOOL NOT NULL DEFAULT '0',
`to_viewed` BOOL NOT NULL DEFAULT '0',
`from_deleted` BOOL NOT NULL DEFAULT '0',
`to_deleted` BOOL NOT NULL DEFAULT '0',
`from_vdate` DATETIME NULL ,
`to_vdate` DATETIME NULL ,
`from_ddate` DATETIME NULL ,
`to_ddate` DATETIME NULL ,
`created` DATETIME NOT NULL
) ENGINE = MYISAM ;

keyboard
08-17-2011, 08:53 PM
Hi everyone,



CREATE TABLE pmsys(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
to VARCHAR(30),
from VARCHAR(32),
title VARCHAR(32),
message VARCHAR(250),
date VARCHAR(30),
ifread VARCHAR(30))


#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 'to VARCHAR(30), from VARCHAR(32), title VARCHAR(32), message VARCHAR(250), d' at line 4


Any help

djr33
08-17-2011, 09:55 PM
Read JShor's message. Did that not fix it?

keyboard
08-18-2011, 12:32 AM
The code I just posted is a differnet one

traq
08-18-2011, 04:26 AM
from is a reserved word (it's a SQL command). It is always good practice to escape table names, column names, etc. using backticks. sql doesn't automatically know that the name you write is a name; it is only after checking it against possible commands/keywords (and finding it doesn't match) that it decides to treat it as a value. this is good for forward-compatibility as well. for example:
CREATE TABLE `pmsys`(
`id` INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(`id`),
`to` VARCHAR(30),
`from` VARCHAR(32),
`title` VARCHAR(32),
`message` VARCHAR(250),
`date` VARCHAR(30),
`ifread` VARCHAR(30)) note that these are backticks ( ` ), not single-quotes ( ' ).

mouseinhome
08-21-2011, 08:36 AM
keyboard1333 didn't show clearly what the error you spotted, so i can't know it exactly. But, i think maybe problem in here is your table name "messages". In past, i used to create tables with some popular name, unfortunately it duplicate with same system name were create before. It can made wrong understand and error here.
Can you try another table name? Maybe it works.

jimmy1
08-21-2011, 02:11 PM
CREATE TABLE `messages` (
`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NULL
`message` TEXT NOT NULL ,
`from` INT( 11 ) NOT NULL ,
`to` INT( 11 ) NOT NULL ,
`from_viewed` BOOL NOT NULL DEFAULT '0',
`to_viewed` BOOL NOT NULL DEFAULT '0',
`from_deleted` BOOL NOT NULL DEFAULT '0',
`to_deleted` BOOL NOT NULL DEFAULT '0',
`from_vdate` DATETIME NULL ,
`to_vdate` DATETIME NULL ,
`from_ddate` DATETIME NULL ,
`to_ddate` DATETIME NULL ,
`created` DATETIME NOT NULL
) ENGINE = MYISAM ;


This code is causing an error. Any help


If you will right what is the error its showing will more helpful to solve your problem.

JShor
08-21-2011, 02:17 PM
If you will right what is the error its showing will more helpful to solve your problem.

This issue was already resolved. It was a visible syntax error.