bnrfly bnrfly - 1 month ago 8
MySQL Question

Error creating table (#1064 - YOU have an error in your sql syntax)

I'm just trying to create a table

persons
with some fields but I got this error
#1064 - YOU have an error in your sql syntax
Here's the query:

CREATE TABLE `persons`(
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`firstName` varchar(100) DEFAULT NOT NULL,
`lastName` varchar(100) DEFAULT NOT NULL,
`gender` enum('male','female') DEFAULT NOT NULL,
`address` varchar(200) DEFAULT NOT NULL,
`dob` date DEFAULT NOT NULL,
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


Can you spotted what's wrong with my query? thank you.

Answer
CREATE TABLE `persons`(
`id` int(11) unsigned NOT NULL AUTO_INCREMENT, 
`firstName` varchar(100) NOT NULL,
`lastName` varchar(100) NOT NULL,
`gender` enum('male','female') NOT NULL,
`address` varchar(200) NOT NULL,
`dob` date NOT NULL,
PRIMARY KEY(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Your can simply leave out DEFAULT in your attribute definitions, since you are not setting a default value and are not allowing NULL values anyway.

Comments