How can I escape a single quote in SQL?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In SQL, you can escape a single quote by doubling it, i.e., you use two single quotes (”) to represent one single quote (‘).
Here’s an example of this in action:
“`
INSERT INTO table (column) VALUES (‘It”s a sample text’);
“`
In this example, the data to be inserted into the table is `It’s a sample text`, which includes a single quote character (`’`). To avoid disrupting the SQL syntax, two single quotes (`”`) are used in its place, escaping the single quote.
Remember, this is for standard SQL. But different SQL implementations may have different ways to escape characters. So, if you’re not sure, it’s better to check the documentation for the specific SQL version or implementation you’re using.