New answers tagged

0

This is old but sad to see the obvious not mentioned. Setting an AUTO_INCREMENT high on every table is a lot more work as it has to be done for every table, and only works for so long until the db grows big enough. None of these even explain what auto_increment_offset is really for! The sensible way is to use auto_increment_increment Set it to 2 or 3 or ...


1

This below worked for me: SELECT count(*) INTO @exist FROM information_schema.columns WHERE table_schema = 'mydatabase' and COLUMN_NAME = 'mycolumn' AND table_name = 'mytable' LIMIT 1; set @query = IF(@exist <= 0, 'ALTER TABLE mydatabase.`mytable` ADD COLUMN `mycolumn` MEDIUMTEXT NULL', 'select \'Column Exists\' status');...


0

Some tools, like DataGrip or Database plugin for Intellij stop execution with unsafe query warning, when update or delete query has no where clause. This can be disabled manually, but if you wish to work with console and be warned but run such scripts often, adding something that always resolves to true seems to be the easiest option.


Top 50 recent answers are included