0

when creating MySQL sql scripts, is it necessary to use quote column name in

`column-name`

?

like:

DROP TABLE IF EXISTS `qs_admin_log`;
CREATE TABLE `qs_admin_log` (
  `log_id` int(10) unsigned NOT NULL auto_increment,
  `admin_name` varchar(20) NOT NULL,
  `add_time` int(10) NOT NULL,
  `log_value` varchar(255) NOT NULL,
  `log_ip` varchar(20) NOT NULL,
  `log_type` tinyint(1) unsigned NOT NULL DEFAULT '1',
  PRIMARY KEY  (`log_id`)
) TYPE=MyISAM ;
?

I saw many scripts use this , is it necessary or is it just a good practice to use?

But if I execute such sql statements in phpMyAdmin, it shows syntax error. Also when I convert MySQL database to MS SQL Server database, those becomes dot sign and MSSQL reports syntax error when executing.

So is it a good MySQL practice to use such quotes when writing SQL statements?

user3205002
  • 25
  • 1
  • 5
  • 1
    It is only necessary if you are using a MySQL reserved word (http://dev.mysql.com/doc/refman/5.7/en/reserved-words.html) or an unusual character (such as a space) for a name. It is not needed anywhere for this SQL. I don't think it is good practice in other cases, because it makes the code harder to read.. The most common delimiter is double quotes, which works in both SQL Server and MySQL. – Gordon Linoff Jan 20 '14 at 02:52
  • Gordon Linoff, thanks! I have the same idea! Unless there is need for MySQL reserved words, there is NO NEED to use such quote anywhere in SQL statements! – user3205002 Jan 20 '14 at 03:42

0 Answers0