Databases, mysql and the forbidden

Databases, mysql and the forbidden

Lets just recapitulate - relational databases are good at ensuring data consistency, right?

So lets try this:

CREATE TABLE user (
  id int NOT NULL AUTOINCREMENT,
  login NOT NULL,
  email NOT NULL
);

And then this

INSERT INTO user (login) VALUES ('mike');

What happens next?

You'd probably expect something along the lines of

ERROR 1364 (HY000): Field 'email' doesn't have a default value

Sorry, no. This is what I got:

Query OK, 1 row affected, 1 warnings (0.02 sec)

Thanks to this sucker:

SELECT @@sql_mode;

Which yields the "informative" empty string. What this means is that strict (other people would call this "normal") SQL mode is off. What happens when mysql is running in this "lax" mode is that columns with no default that aren't specified in INSERT statements and with a NOT NULL constraint are silently changed to empty strings.

Which lead me to the conclusion that some options should just be forbidden.

...and I'm sending my thoughts to the family of the developer who decided to disable strict sql mode. It must be a struggle. Every day.

Illustration by A Syn

Thanks for the list, Søren Lund. Most amusing!

Like
Reply

I personally stay away from MySQL if possible. "It's not a bug - it's a gotcha. A "gotcha" is a feature or function which works as advertised - but not as expected. " - http://sql-info.de/mysql/gotchas.html

Like
Reply

To view or add a comment, sign in

More articles by Michael Zedeler

  • System bankrupcy and technical debt

    Slow teams and non-existing standards As some point you may find yourself working with or as member of a development…

    7 Comments
  • 4 paths to utterly useless user stories

    So whats the big deal with user stories? Since the proliferation of agile software development, I've had the…

    1 Comment
  • What is a git ninja exactly?

    The git toolchain is so widely used, that most developers have to learn how to use it to some reasonable degree. I'm…

    1 Comment

Explore content categories