Come correggere l'errore “Hai un errore nella sintassi; controlla il manuale che corrisponde alla versione del tuo server MySQL per la sintassi corretta da utilizzare vicino a... ”?
Questo tipo di errori si verificano quando si utilizza una sintassi errata. Vediamo un esempio in cui abbiamo creato una tabella e si presenta lo stesso errore “1054”.
Ecco la tabella:
mysql> create table DemoTable689(
UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
UserName varchar(100),
UserLoginDate date(100) NOT NULL
);
Ciò produrrà il seguente output, ovvero un errore per l'utilizzo errato della sintassi:
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
Correggiamo ora l'errore 1054. Per questo, è necessario utilizzare solo DATE NOT NULL. Creiamo innanzitutto una tabella:
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)
Inserisci alcuni record nella tabella utilizzando il comando di inserimento:
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)
Visualizza tutti i record dalla tabella utilizzando l'istruzione select :
mysql> select *from DemoTable689;
Ciò produrrà il seguente output. Ora abbiamo corretto l'errore:
+--------+----------+---------------+
| 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)