问题
Does anybody know what's the maximum number of columns/values you can insert into a table (mysql)? I get an error for... IDK... 20 columns/values? (yes, #_of_col = #no_of_val)
INSERT INTO comenzi (a,b,c,d,e,f,...)
VALUES (1,2,3,4,5,6,...)
回答1:
You can have more than 20 columns in a table so I don't think that is your problem.
Most likely you have the wrong number of columns in your values list or one of your column names is a keyword.
You said you've already checked that number of values is correct. In my experience counting 20 things by hand is very difficult so you might want to double-check that you've counted correctly.
But assuming that isn't the problem then I'd guess that it's probably because one of your column names is a reserved keyword. Surrounding your column names with backticks prevents them being parsed incorrectly:
INSERT INTO comenzi (`a`, `b`, `c`, `d`, `e`, `f`, ...)
VALUES (1, 2, 3, 4, 5, 6, ...)
You should also make sure that if you have any strings in your value list that they are quoted and properly escaped if necessary.
回答2:
The hard limit is 4096 columns per table, with a maximum row size of 65,535 bytes (Source: MySQL Documentation).
来源:https://stackoverflow.com/questions/3436331/maximum-number-of-columns-values-you-can-insert-into-a-table-mysql