Why the "quotes" in the INT data?

Asked

Viewed 111 times

3

In the Mysql Workbench, when we do not enter a record by query, and yes manually, when giving the APPLY, to query is displayed before execution.

Example of a query composed of the Mysql Workbench:

INSERT INTO `nomedobanco`.`tabela` (`id`, `resumo`, `descricao`, `grupo`, `solicitante`, `atendente`, `status`) 
VALUES ('171', 'Teste', 'Testando', '7', '1', '2', 'N');

How it would also work:

INSERT INTO `nomedobanco`.`tabela` (`id`, `resumo`, `descricao`, `grupo`, `solicitante`, `atendente`, `status`) 
VALUES (171, 'Teste', 'Testando', 7, 1, 2, 'N');

Doubts

  • Why the Mysql Workbench quotes values INT?
    • It does not identify the type of fields and ends up inserting everything "as a string"?

1 answer

1


First of all, this is not exclusive to Workbench. I used other tools and the SqlYog for example, does exactly the same thing.

This is to optimize the generation of query. Like the MySql does not complain of receiving integer values between quotation marks, these programs use this artificial so you do not need to check the type of column to put or not the value between quotation marks.

But be careful when using this device. In the case of INSERT and in the SET of UPDATE, that is, attributions, I don’t see so much problem. But in WHERE you may have some issues related to the performance of query. This is because, when comparing text with number, the MySql performs a type conversion, so in such cases, the ideal is to use numbers without quotes, if compared to numbers.

Note that the Workbench also places numerical values between quotation marks in comparisons.

In the INSERT it probably also performs this conversion, but as the amount of data is usually small becomes irrelevant (it is not true for all cases).

Browser other questions tagged

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