PDA

View Full Version : mySQL error, wrong syntax?



cursed
01-11-2008, 12:57 AM
An error appears when I run the following mySQL statement..


CREATE TABLE `actions` (
`id` int(10) unsigned NOT NULL auto_increment,
`actionid` tinyint(3) unsigned NOT NULL default '0',
`playerid` smallint(6) NOT NULL default '0',
`time` datetime NOT NULL default '0000-00-00 00:00:00',
`map` tinyint(3) unsigned NOT NULL default '0',
`xpos` smallint(5) unsigned NOT NULL default '65535',
`ypos` smallint(5) unsigned NOT NULL default '65535',
`parameters` varchar(255) collate latin1_general_ci NOT NULL default '',
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci;


and the error message..



#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 'collate latin1_general_ci NOT NULL default '',
PRIMARY KEY

MySQL version : 4.0.27-standard
Help would be appreciated!

djr33
01-11-2008, 01:08 AM
If I'm right, this is funny.

NOT NULL default '',
Not null, yet you specify the default value IS null. ;)

cursed
01-11-2008, 01:30 AM
If I'm write, this is funny.

NOT NULL default '',
Not null, yet you specify the default value IS null. ;)

Thanks for the reply.. however I'm getting the same error, except with the NULL.

error is as follows:



#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 'collate latin1_general_ci NULL,
PRIMARY KEY (`id`)
) ENGIN

djr33
01-11-2008, 04:36 AM
Well, you can have it not null.

See, NULL is a keyword that means "cannot be empty". If you specified it as "null" it would be always empty-- in other words, worthless. You DO want to store data. "NOT NULL" specifies that there must always be a value for it. Using '' means null, an empty string. The way to get around this is to actually specify a value, like 0, or 'new'. You could also just remove "NOT NULL", which would leave it as allowed to be null, and that's just fine. If so, you can probably remove the default '' as well, leaving that whole part of the command off.

I'm not sure if default='' or default '' is the right syntax, so you might play with that too.

tech_support
01-11-2008, 04:55 AM
Works fine for me.