我的数据库有一些语法错误但我无法找到它们,所以我想我可以在这里问一下

时间:2017-06-28 08:55:41

标签: mysql database mariadb

所以这是我的数据库

CREATE TABLE IF NOT EXISTS `users` (
  `userId` int(8) NOT NULL AUTO_INCREMENT,
  `userName` varchar(55) NOT NULL, 
  `password` varchar(55) NOT NULL, 
  `firstName` varchar(55) NOT NULL, 
  `lastName` varchar(55) NOT NULL, 
   PRIMARY KEY (`userId`) ) 
INSERT INTO `users` (`userId`, `userName`, `password`, `firstName`, `lastName`) 
  VALUES (24, 'joel', '', 'Joel', 'Thomas'), (26, 'merlinsofia', '', 'merlin', 'sofia'), (27, 'matt', '', 'Matthew', 'Matthew'), (28, 'mike', '', 'Mike', 'Anto')

这些都是错误......

在分析过程中发现了6个错误。

Unexpected beginning of statement. (near "`userId`" at position 257)
Unexpected beginning of statement. (near "`userName`" at position 267)
Unexpected beginning of statement. (near "`password`" at position 279)
Unexpected beginning of statement. (near "`firstName`" at position 291)
Unexpected beginning of statement. (near "`lastName`" at position 304)
Unrecognized statement type. (near "VALUES" at position 316)

SQL查询:

CREATE TABLE IF NOT EXISTS `users` ( 
 `userId` int(8) NOT NULL AUTO_INCREMENT, 
 `userName` varchar(55) NOT NULL, 
 `password` varchar(55) NOT NULL, 
 `firstName` varchar(55) NOT NULL, 
`lastName` varchar(55) NOT NULL, PRIMARY KEY (`userId`) ) 
INSERT INTO `users` (`userId`, `userName`, `password`, `firstName`, `lastName`) 
   VALUES (24, 'joel', '', 'Joel', 'Thomas'), (26, 'merlinsofia', '', 'merlin', 'sofia'), (27, 'matt', '', 'Matthew', 'Matthew'), (28, 'mike', '', 'Mike', 'Anto')

MySQL说:文档

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'INSERT INTO `users` (`userId`, `userName`, `password`, `firstName`, `lastName`) ' at line 1

我似乎无法发现错误,但请记住我是初学者,所以我想在这里寻求帮助!

1 个答案:

答案 0 :(得分:1)

创建和插入需要由;分隔。这就是全部。

试试这个:

CREATE TABLE IF NOT EXISTS `users` (
  `userId` int(8) NOT NULL AUTO_INCREMENT,
  `userName` varchar(55) NOT NULL, 
  `password` varchar(55) NOT NULL, 
  `firstName` varchar(55) NOT NULL, 
  `lastName` varchar(55) NOT NULL, 
   PRIMARY KEY (`userId`) ) ;
INSERT INTO `users` (`userId`, `userName`, `password`, `firstName`, `lastName`) 
  VALUES (24, 'joel', '', 'Joel', 'Thomas'), (26, 'merlinsofia', '', 'merlin', 'sofia'), (27, 'matt', '', 'Matthew', 'Matthew'), (28, 'mike', '', 'Mike', 'Anto')