What’s the difference when you use Inary in the Where clause?

Asked

Viewed 539 times

4

  • What is Binary and what he does?
  • What is the difference generated when using the Binary in a query in the Mysql and when it does not use the Binary?

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

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

  • Is there any difference in others SGBD’s, or the Binary nor exists in others SGBD’s?

1 answer

5


First, select should be 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 Dbms and in Mysql its function is to force an exact comparison, that is, a comparison case-sensitive, byte to byte.

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

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

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

  • 2

    In C#, JAVA, for example, the syntax says that the logical operator AND should be written like this: && and in PL/SQL, which is language that Sgdbs understand the syntax says it should be written like this: AND

Browser other questions tagged

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