What's the difference when using binary in the where clause?

4
  • What is Binary and what does it do?
  • What is the difference generated when using Binary in a query in MySQL and when not using Binary ?

SELECT email, senha from login WHERE usuario = ? && senha = ?

SELECT email,senha from login WHERE BINARY usuario = ? && BINARY senha = ?

    Is there any difference in other DBMS's , or Binary and does not exist in other DBMS's ?
asked by anonymous 19.05.2017 / 15:26

1 answer

4

First, the select should look like this:

  SELECT email, senha from login WHERE usuario = ? and senha = ?

and not like this:

  SELECT email, senha from login WHERE usuario = ? && senha = ?

BINARY does not exist in other DBMSs and in MySQL its function is to force an exact comparison, that is, a case-sensitive comparison, byte to byte.

SELECT 'senha' = 'seNha'  -- 1 - true

SELECT BINARY 'senha' = 'SeNha'  -- 2 - false

Another use is in creating the table, when using the word BINARY you force that the comparison for that column is case-sensitive , byte to byte.

    
19.05.2017 / 15:35