For example, if I use the GUI to perform an INSERT
, the console will log the following execution:
Why does each item have apostrophes (aside from NULL
)?
I know that I can do a literal INSERT
via terminal or PHP without the apostrophes, especially when referencing the table or columns (and several tutorials only apply apostrophes around the insert values, not table or column references). I know that this isn't exactly a, "help me question" but I am very curious if there's a reason behind this. Thanks.
Best Answer
Those around values are single quotes -
'
and denote string values. Numbers should not be quoted if they are supposed to go to a numeric type column but in PhpMyAdmin every input field is textual by default so it probably just tries to stay safe with quoting the'5'
too, MySQL can convert the type when needed.The other type are backticks
`
and it is a different character. MySQL uses it to quote identifiers (names of column, tables, indexes etc.). It is not needed when you use normal identifiers likename
oremail
but it is needed for others:`insert`
or`order`
- not a good idea to create tables with such columns, but sometimes it already exists and you just need to query it.`column named X`
- again better not to name your columns like this, but it is often used for column aliases in selects.
For PMA it is just simple to quote every identifier than to check if it is safe or not to go unquoted.