如何修復錯誤“You have an error in your syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near… ”?
這種錯誤出現在您使用了錯誤的語法時。讓我們來看一個建立表的示例,其中出現了相同的錯誤“1054”。
以下是表格:
mysql> create table DemoTable689( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserLoginDate date(100) NOT NULL );
這將產生以下輸出,即錯誤的語法使用錯誤:
ERROR 1064 (42000): 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 '(100) NOT NULL )' at line 5
現在讓我們修復錯誤 1054。為此,您只需要使用 DATE NOT NULL。讓我們先建立一個表:
mysql> create table DemoTable689( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserLoginDate date NOT NULL ); Query OK, 0 rows affected (0.68 sec)
使用 insert 命令在表中插入一些記錄:
mysql> insert into DemoTable689(UserName,UserLoginDate) values('John',DATE(NOW()));
Query OK, 1 row affected (0.40 sec)
mysql> insert into DemoTable689(UserName,UserLoginDate) values('Chris','2018-01-21');
Query OK, 1 row affected (0.21 sec)
mysql> insert into DemoTable689(UserName,UserLoginDate) values('Robert',CURDATE());
Query OK, 1 row affected (0.20 sec)使用 select 語句顯示錶中的所有記錄:
mysql> select *from DemoTable689;
這將產生以下輸出。現在,我們已經修復了錯誤:
+--------+----------+---------------+ | UserId | UserName | UserLoginDate | +--------+----------+---------------+ | 1 | John | 2019-07-21 | | 2 | Chris | 2018-01-21 | | 3 | Robert | 2019-07-21 | +--------+----------+---------------+ 3 rows in set (0.00 sec)
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP