6
ocwjay
3y

Me: *newly learning MySQL*

Also me: time to buy wedding rings for my pinky finger and the caps lock key

Comments
  • 5
    Keywords aren't case-sensitive in SQL.
  • 2
    @Oktokolo SERIOUSLY? Every time I look anything up or read through my class reading, it's all very specifically uppercased for certain things. Thanks for the tip!
  • 4
    @ocwjay
    Don't thank me! Thank @MrObvious as it is him who teached me the secrets of SQL (the third may frighten you)...
  • 3
    @ocwjay keywords aren't case sensitive, but if I ever see a query in a codebase where it's not uppercase for keywords..... so help me I'll change it.
  • 2
    @C0D4 What’s your stance on no sql DBs using caps for the collections? Seems like it’s not as much of a convention there (been using mongo for a few years now), but from all the years of using SQL I do tend to still use them for collection names at least.
  • 1
    @EstrnAdventures I use snake_case but that's probably more to do with doing the same for tables in SQL for countless years.

    Plus it makes the queries easier to read IMO.

    SELECT
    this_field,
    this_other_field
    FROM that_table
    WHERE this_thing <= that_thing;
  • 1
    @C0D4
    Lets meet in the middle: Title case...

    "Select count(*) as cunt From foobars F
    Where someField is Not Null and anotherField in (1, 3, 5)"
  • 1
    @Oktokolo I see that a lot, it's so hard to read for large queries. Which is what I typically deal with (200+ lines) so formatting is a must for me.
  • 1
    @C0D4 hahaha heard that! I'll keep it in mind as a good practice then
  • 2
    @ocwjay The nice thing about SQL, which can pretty much fuck you up, is that there small nuances in how things are handled.

    E.g.

    sys.format_bytes calls the format_bytes function from the sys schema / database.

    FORMAT_BYTES is an internal function, now in performance schema, but globally callable without schema prefix.

    https://dev.mysql.com/doc/refman/...

    The upper / lower casing is used through the docs.

    One of the reasons I told many interns that I have a zero tolerance policy against unformatted SQL.

    The "principle" above of calling a schema / database function vs. an internal function is pretty common, especially when you e.g. need to support many versions of MySQL and need polyfills or user defined functions.

    The mistake of using internal function and query hitting the database with a lower version of MySQL where the function is not supported can be very fatal ;)

    TLDR: Casing is important and if there's an style given in a documentation of the RDBMs, follow it closely. It might make your life much easier.
  • 0
    @IntrusionCM thank you for the tips! I'll continue marrying my pinky finger to my caps lock key then haha
  • 1
    @C0D4
    The titlecase was meant as a joke.
    I guess it is like with the rule 34 - if i can think about a worse style, it probably is in use somewhere...
  • 1
    @Oktokolo I'm just waiting for the day we have

    SeLeCt X fRoM y WhErE mYbRaIn_HuRtS = tRuE
  • 1
    @C0D4 the door is in the top left corner, you may leave now 🤣🤣🤣
  • 1
    @C0D4
    Well, still better than anything a mathematician could come up with...
  • 0
    There is actually a flag for being case sensitive in MySQL but its FALSE by default.

    Thats the case in most DBs to my knowledge, but from MariaDB docs, it depends on OS. For Windows, it's not case-sensitive. For Linux, Database, table, table aliases and trigger names are affected by the systems case-sensitivity, while index, column, column aliases, stored routine and event names are never case sensitive.
Add Comment