Doubt Mysql Insert

Asked

Viewed 158 times

1

Good morning, I’m trying to make an Insert,plus this giving error and seems to be in the hour field,could help me identify what is wrong: Follows the Insert and the error.

INSERT INTO senhas 
                                                 (senha_id,
                                                  senha_setor_id,
                                                  senha_tipo_id,
                                                  senha_numero,
                                                  senha_data,
                                                  senha_hora)
                                          VALUES 
                                                 ('1',
                                                  '1',
                                                  '1',
                                                  '1',
                                                  '2016-03-01',
                                                  '10:03:00');

Follow the return:

Error Code: 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 '' at line 14 0.000 sec

The fields are:

senha_id        = int (11) 
senha_setor_id  = int (11) 
senha_tipo_id   = int (11)
senha_numero    = int (11) 
senha_data      = date 
senha_hora      = time

As indicated by our colleague @jbueno were removed the '' from the int fields.

INSERT INTO senhas
                                             (senha_id,
                                              senha_setor_id,
                                              senha_tipo_id,
                                              senha_numero,
                                              senha_data,
                                              senha_hora)
                                      VALUES 
                                             ('',
                                              1,
                                              1,
                                              1,
                                              '2016-03-01',
                                              '10:03:00');
  • Have you tested this query in phpmyadmin or Workbench? it seems that this question Sert is not the same that has been tested.

  • @rray You saw that the error shows a double quote (or two single quotes) [...] syntax to use near ''? It really seems that this is not the insert that is being tested.

  • @jbueno the question Insert is right even with simple quotes (if the value is numerical it is converted), for me it is two single quotes together or an empty value. I also think that the problem Insert is another.

  • Because @rray, I had no idea that Mysql converted the values, but I tested it out of curiosity and it worked. That made me think that the insert problem is another...

  • Checks whether Foreign Key (FK) actually exists in other tables.

  • You can mark the jbueno answer as accepted, the green light means the problem has been solved, if you have any questions you can see, How and why to accept an answer?

Show 1 more comment

1 answer

3

You are entering all fields as varchar.

Your insert should look like this

INSERT INTO senhas 
     (senha_id,
      senha_setor_id,
      senha_tipo_id,
      senha_numero,
      senha_data,
      senha_hora)
VALUES 
     (1,
      1,
      1,
      1,
      STR_TO_DATE('01, 03, 2016','%d,%m,%Y'),
      STR_TO_DATE('10:03:00','%h:%i:%s'));
  • Continues: Error Code: 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 '' at line 13 0.000 sec

  • You have the database selected?

  • 1

    I just tested, your Insert is not wrong. The problem is another.

  • yes, I’m with the selected base

  • 1

    @Otaciobarbosa O insert question really is equal to what is being tested?

  • I managed, it worked, I will supplement in the question

  • Thank you all for your help.

  • @jbueno Testing the table of our friend and his Insert, I realized that there was an error when running your Insert on account of the word '10:03:00a' and when removed it worked normal... it would not be the case to edit your reply ?

  • @Lucasaugusto Typo, but anyway my answer is not correct, as (well) punctuated by rray Mysql does the automatic conversion of values...

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.