错误1064(42000):您的SQL语法有错误;
技术问答
200 人阅读
|
0 人回复
|
2023-09-14
|
我有一个MySQL命令:5 D$ A& o9 s, l" ~ M
CREATE DATABASE IF NOT EXISTS courses;
1 E' w, f' ^# o- w8 a* ?% zUSE courses
+ w! O& Y$ D$ t3 a) @3 WCREATE TABLE IF NOT EXISTS teachers(
' {$ u) C- \! i3 a id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
, b0 A2 i0 c& _, f$ y9 K name VAR_CHAR(50) NOT NULL,2 b0 i1 O4 W# l1 F/ \* d; F
addr VAR_CHAR(255) NOT NULL,' [% W* `% [2 x
phone INT NOT NULL,& R* M( J; K1 e, z/ E" F
);: g* G$ P/ X5 t, l
当我运行它时,我得到一个错误:8 {/ n% C; x8 v; h" o
ERROR 1064 (42000): You have an error in your SQL syntax; check the
3 u0 I( ]) w8 U0 Z5 \ Gmanual that corresponds to your MySQL server version for the right
* b5 x7 L) R; B3 h y$ Asyntax to use near 'VAR_CHAR(50) NOT NULL, addr VAR_CHAR(255) NOT
7 ~+ w) Q* O" r4 y2 r% U0 `NULL, phone INT NOT NULL, )' at line 3" c3 p9 \# D: L7 v; K! t. _- h
0 L6 u# Y8 [, F: K/ t3 P解决方案:
& }* y: M% V8 y' d
8 t5 U" N* y3 i
& T5 r- g" W9 T7 }3 E1 q V \7 w2 j1 o3 |2 A% g& @
是varchar不是var_char; |" m5 i+ c$ ~$ ~5 n- N
CREATE DATABASE IF NOT EXISTS courses;2 z/ S7 ~+ k8 U) z5 J8 _
USE courses;5 }5 S4 D$ d% f# w) `
CREATE TABLE IF NOT EXISTS teachers(0 @+ S; _1 W z% O
id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
6 g& f1 _) ?* P- f- x2 N name VARCHAR(50) NOT NULL,/ q# [$ s0 Z+ R2 F3 t' I; f3 u
addr VARCHAR(255) NOT NULL,
. t% i) l0 _0 F; v2 c phone INT NOT NULL; |' r% n& f& E! r
);; U# o7 I" B! @3 W% M
您应该使用SQL工具来可视化可能出现的错误,例如 MySQL Workbench 。 |
|
|
|
|
|