- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I insert a special character such as ' (single quote) into MySQL?
To insert a special character such as “ ‘ “ (single quote) into MySQL, you need to use \’ escape character. The syntax is as follows −
insert into yourTableName(yourColumnName) values(' yourValue\’s ');
To understand the above syntax, let us create two tables. The query to create first table is as follows −
mysql> create table AvoidInsertErrorDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Sentence text -> ); Query OK, 0 rows affected (0.53 sec)
Now you can insert special character such as ‘ in the table using insert command. The query is as follows −
mysql> insert into AvoidInsertErrorDemo(Sentence) values('a woman\'s hat'); Query OK, 1 row affected (0.16 sec) mysql> insert into AvoidInsertErrorDemo(Sentence) values('Mrs. Chang\'s house'); Query OK, 1 row affected (0.31 sec)
Display all records from the table using select statement:
mysql> select *from AvoidInsertErrorDemo;
The following is the output −
+----+--------------------+ | Id | Sentence | +----+--------------------+ | 1 | a woman's hat | | 2 | Mrs. Chang's house | +----+--------------------+ 2 rows in set (0.00 sec)
- How to display a single quote text as a column value in MySQL?
- How do I insert multiple values in a column with a single MySQL query?
- How do I insert a NULL value in MySQL?
- How to insert into two tables using a single MySQL query?
- How do I insert a JPEG image into a Python Tkinter window?
- How do I get the id after INSERT into MySQL database in Python?
- How do I insert a record from one Mongo database into another?
- How to insert only a single column into a MySQL table with Java?
- How can I update MySQL table after quoting the values of a column with a single quote?
- MySQL: How can I find a value with special character and replace with NULL?
- How do we insert/store a file into MySQL database using JDBC?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?
- Insert JSON into a MySQL table?
- Split a string and insert it as individual values into a MySQL table?
- How do I insert all elements from one list into another in Java?