How to insert a record with Apostrophe (') in one of
the character field ?
SOLUTION
Convert all the single apostrophe ( ' ) to a pair of apostrophe ('').
Please take note, use two single quotes and
not a double quote.
For example, you want to insert a new customer record into the
Customers table. The customer name that you want to insert is Liu's Brothers.
INSERT INTO Customers (CustID, Name, Address, City,
Country, PostalCode, Telephone, Fax)
VALUES ('CUST006', 'Liu's Brother',
'55 Grizzly Peak Rd.', 'Butte', 'USA', '59810',
'030-748080', 030-7405805)
If you run the above SQL statement, you will hit into error because
SQL will not accept Liu's Brother. To solve this problem, you have to replace
the single apostrophe ( ' ) with a pair of apostrophes (''). The statement
should looks like below:
INSERT INTO Customers (CustID, Name, Address, City,
Country, PostalCode, Telephone, Fax)
VALUES ('CUST006', 'Liu''s Brother',
'55 Grizzly Peak Rd.', 'Butte', 'USA', '59810',
'030-748080', 030-7405805)
Table: Customers
| CustID |
Name |
Address |
City |
Country |
PostCode |
Phone |
| CUST001 |
Maria Anders |
Obere Str. 57 |
Berlin |
Germany |
12209 |
030-0074321 |
| CUST002 |
Ernst Handel |
Kirchgasse 6 |
Graz |
Austria |
8010 |
7675-3425 |
| CUST003 |
Helen Bennett |
Garden House Crowther Way |
Cowes |
UK |
PO31 7PJ |
(198) 555-8888 |
| CUST004 |
Paula Wilson |
2817 Milton Dr. |
Albuquerque |
USA |
87110 |
(505) 555-5939 |
| CUST005 |
Liu Wong |
55 Grizzly Peak Rd. |
Butte |
USA |
59801 |
(406) 555-5834 |
.