Jump to content

Can't get this SQL code to insert


Paul-D

Recommended Posts

DROP TABLE IF EXISTS `rain-accounts`;
CREATE TABLE IF NOT EXISTS `rain-accounts` (
  `rainID` varchar(10) DEFAULT NULL,
  `AccountDate` varchar(10) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
 

INSERT INTO rain-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08');
 

It was originaly

INSERT INTO rain-accounts (rainID , date) VALUES ('5b6acefb' , '2018-08-08'); But I thought that you may not be able to have a field called date.

Link to comment
Share on other sites

The problem is your table name. To be more precise, the "-" in the name casue it to be interpreted as "rain minus accounts".

You need backticks around the name (or avoid hyphens in favour of underscores in identifiers).

Use DATE type, not varchar, for dates. Even though "date" is keyword, and better avoided, it would have been accepted as it is not reserved.

mysql> DROP TABLE IF EXISTS `rain-accounts`;
Query OK, 0 rows affected, 1 warning (0.01 sec)

mysql> CREATE TABLE IF NOT EXISTS `rain-accounts` (
    ->   `rainID` varchar(10) DEFAULT NULL,
    ->   `AccountDate` varchar(10) DEFAULT NULL
    -> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.15 sec)

mysql> INSERT INTO rain-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08');
ERROR 1064 (42000): 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 '-accounts (rainID , AccountDate) VALUES ('5b6acefb' , '2018-08-08')' at line 1

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.