0

I am trying to insert a column with column name 00:18:e7:f9:65:a6 with the statement

ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT 

...but it throws an error:

/* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"00:18:e7:f9:65:a6" INT' at line 1 */

in Heidi SQL. I am using MySQL database.

When I try to add the column manually b going to the structure of the table it works and does not give any error but when I run this statement it does not allow me. How can I solve this?

Bud Damyanov
  • 30,171
  • 6
  • 44
  • 52
user1583647
  • 1,227
  • 2
  • 24
  • 48

4 Answers4

3

I just ran your query:

ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT 

and got the same error. I then ran:

ALTER IGNORE TABLE tblwifi_information ADD `00:18:e7:f9:65:a6` INT 

and it worked. Pretty sure you need to change " to `

Fail with double qoutes: Failed with double quotes

Success with backticks: Success with backticks

Mark Miller
  • 7,442
  • 2
  • 16
  • 22
  • Hmmm, I'm not sure but I suspect that it could have something to do with your php, and not the query itself. If you haven't done so already, I would try executing another very basic query with php, like `SELECT * FROM ...` just to confirm your db connection is working ok. – Mark Miller May 09 '14 at 03:06
2

use backticks for columnname

change

ALTER IGNORE TABLE tblwifi_information ADD "00:18:e7:f9:65:a6" INT 

TO

ALTER IGNORE TABLE tblwifi_information ADD `00:18:e7:f9:65:a6` INT 

SQL FIDDLE

Nagaraj S
  • 13,316
  • 6
  • 32
  • 53
1

To add something to the story, when querying multiple tables, you have to use following expression:

`tablename`.`columnname`

(NOT `tablename.columnname` )

I took me some time to figure it out, so I hope it helps someone :)

Example:

SELECT * 
FROM tb_product p
JOIN tb_brand b ON (  `p`.`tb_brand:IDbrand` =  `b`.`IDbrand` ) 
WHERE IDfamily = 2
0

i dont really know what you are trying to achive here pal. instead of:

00:18:e7:f9:65:a6

to

00_18_e7_f9_65_a6

then adjust your code to replace ":" to "_" in php or mysql.

in sql:

Replace(table_name, ':', '_');

in PHP:

srt_replace(':','_',$query);
Viscocent
  • 2,024
  • 2
  • 19
  • 26