Friday, October 19, 2012

Backticks in INSERT Query in PhpMyAdmin

I just want to share an experience while trying INSERT SQL query in MySql. I was working on MySQL server version: 5.5.16.

I have one employee details table called "emp" which has the following fields..
emp_id, emp_name, emp_sal, emp_address, emp_tel

The field names are quite self-explanatory. I faced problems when I wanted to inserted a row with only emp_id and emp_name values. 

INSERT into emp ("emp_id","emp_name") values("php-002","Chandan");

The above statement fell flat on its face. MySQL gave me an error saying syntax error.  However, I had corrected the statement by using backtick operator as a wrapper for field names. This is shown below.

INSERT into emp (`emp_id`,`emp_name`) values("php-002","Chandan");

Even if I leave the field names without applying any wrapper, it still works.

INSERT into emp (emp_id,emp_name) values("php-002","Chandan");

Hope this post was useful.

No comments: