新增列的SQL语句出现MariaDB语法错误,请求排查原因
Ah, I see the issue here—you've run into a common syntax quirk with ALTER TABLE when adding multiple columns in MariaDB. Let's break this down:
The Root Cause
Your current query is missing parentheses around the multiple column definitions. MariaDB expects that when adding more than one column, you wrap all of their definitions in a set of parentheses. Without them, the database gets confused after the first column and throws a syntax error at the second DECIMAL declaration.
The Corrected SQL Statement
Here's the fixed version of your query:
ALTER TABLE counties ADD ( public_schools DECIMAL(5,4), public_trans DECIMAL(6,5) );
Why This Works
- When adding a single column, parentheses are optional (e.g.,
ALTER TABLE counties ADD public_schools DECIMAL(5,4);is valid). - When adding multiple columns, MariaDB requires you to group all column definitions inside parentheses to properly parse the list of columns you're adding.
Just to confirm: DECIMAL(6,5) is a valid data type in MariaDB (it allows 1 digit before the decimal point and 5 after), so that part of your original query wasn't the problem—just the missing parentheses for multiple columns.
内容的提问来源于stack exchange,提问作者Daniel E

