PhpMyAdmin中SQL建表语句报错#1064,请求排查语法问题
Hey, I see where the problem is! That #1064 error is popping up because of how you defined the price column's data type.
MySQL requires that if you specify precision for the DOUBLE type, you need to provide two arguments: DOUBLE(M, D). Here's what those mean:
M: The total number of digits (both integer and fractional parts combined)D: The number of digits after the decimal point
Your code uses DOUBLE(10) which only provides the first argument—this violates MySQL's syntax rules for the DOUBLE type, hence the error.
Fixes you can use:
- Skip precision specification entirely (let MySQL use default settings):
CREATE TABLE products( id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), info TEXT, price DOUBLE );
- Specify both total digits and decimal places (example: 10 total digits, 2 after decimal):
CREATE TABLE products( id INT(10) NOT NULL AUTO_INCREMENT PRIMARY KEY, title VARCHAR(255), info TEXT, price DOUBLE(10, 2) );
Quick side note:
If you're storing currency values (like product prices), I'd actually recommend using DECIMAL(M, D) instead of DOUBLE. Floating-point types like DOUBLE can have precision loss with decimal values, but DECIMAL stores exact numeric values—perfect for money-related data. For example:
price DECIMAL(10, 2)
内容的提问来源于stack exchange,提问作者Noname Noname

