Can I avoid sql_mode on my query?

5.4k Views Asked by At

I see that I have this code at the end of a table that I want to insert on my db :

/*!40000 ALTER TABLE `to_import` ENABLE KEYS */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

When I try to execute the query on phpMyAdmin, I get #1231 - Variable 'sql_mode' can't be set to the value of 'NULL' and I don't understand why.

So, can I remove that /*!40101 SET SQL_MODE=@OLD_SQL_MODE */; ? Is it so important? Tried to learn about this, but in fact I don't understand what it do.

1

There are 1 best solutions below

0
On BEST ANSWER

Probably there is an SET @OLD_SQL_MODE = @@sql_mode; SET SQL_MODE='something' above the table definition. Apparently you forgot to include that in your copied SQL.

Your export tool wants the ALTER TABLEs be executed with a certain SQL mode and sets that before the ALTER TABLEs. To reset it later to the value it was before, it stores the current value in a variable called @OLD_SQL_MODE. The purpose of that line is to reset the SQL_MODE to whatever it was before.

So you need to have both, the SET above and the SET below your table definition or none of them.