创建表错误(#1064 -在sql语法中有错误)

时间:2023-01-30 19:15:57

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:

我只是想创建一个包含一些字段的表person,但是我得到了这个错误#1064 -您的sql语法中有一个错误这是查询:

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.

你能发现我的查询有什么问题吗?谢谢你!

1 个解决方案

#1


4  

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;

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

您可以在属性定义中省去DEFAULT,因为您没有设置默认值,而且也不允许空值。

#1


4  

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;

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

您可以在属性定义中省去DEFAULT,因为您没有设置默认值,而且也不允许空值。