Jump to content
Paul-D

Can't get this SQL code to insert

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.

Share this post


Link to post
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

 

Edited by Barand

Share this post


Link to post
Share on other sites

Consider a simple underscore instead of the hyphen. Or nothing at all and just have it as one word.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.