I need to add the city name O'Fallon to my database, but since it has the single quote in it, the database thinks that I am just wanting to put the "O" in the field. How do I add this the whole city name to my field?
Three answers:
sspade30
2012-03-04 14:13:30 UTC
you can put the entire thing in double quotes.
of course, if you need to insert something with double quotes...
you can also use double single quotes:
update table set name='O''Fallon'
EDIT:
so it should be:
insert into Customers (City)
values ('O''Fallon')
?
2012-03-06 01:14:47 UTC
this is pretty simple. just have to use both double and single quote. try this:
INSERT INTO customers (City) VALUES ("O'Fallon");
need some more development help? check us out http://nexusstrategiesllc.com
J
2012-03-04 22:15:42 UTC
It depends on your database, one option is to simply do: O''Fallon (using two single-quotes).
Also, you can occasionally preface it with a backslash (\) or surround it with square brackets ([]) thus escaping it, but that depends on the DBMS that you're using.
ⓘ
This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.