SQL Code Jockeys – Beware the Apostrophe

For my fellow SQL code jockeys beware the apostrophe when doing text inserts to your databases. It does not magically comment out and will be taken as part of your code insert, not text.

I am working on a network of template websites where users can create a template to start from with the push of a button. The desired finished effect was to create their own unique database they could build on, but I wanted to insert text instructions into their displays to lessen their learning curve and make the initial user experience a little easier.

In my text inserts I automatically used words like “don’t” and “you’re” without thinking. I had naively assumed it would comment out like text in html. After looking at it I realized this was magical thinking, and the code won’t know to comment out, so takes the apostrophe as part of the code, not text.

Wasted an hour of my time so hopefully this will save someone else more time. But if you’re like me, you’d probably rather figure it out yourself and by the time you look for a solution on the internet more than an hour has already gone by. D’oh!

So the quick fix, just spell out your words for readable SQL text inserts, don’t use the apostrophe. Sure it’s a little square. But I doubt this will bother too many people reading off a database insert.

4 thoughts on “SQL Code Jockeys – Beware the Apostrophe

  1. I’ve been researching this exact issue. Unfortunately for me I need to find an answer because I need to use the apostrophe in the Surname field of my database. Many names have apostrophe’s within them, and people get rather picky as to how their name is spelled.

    I’ll let you know what I find….

  2. That barely took me a half hour – codefixer.com – never heard of them before, but their fix worked for me 🙂

    Use the Replace function to change a single apostrophe to a double apostrophe (NOT a double quotation), which SQL will interpret as a single apostrophe and all works excellent……

Leave a Reply

Your email address will not be published. Required fields are marked *