Search code examples
mysqlconstraintsddl

SQL constraints check <>


I just want to know what does the symbol <> after the keyword check do??

Example:

create table DistancesTbl(
   from varchar(100) not null,
   to varchar(100) not null,
   km smallint not null,
   primary key(from, to),
   constraint check_from_to check (from <> to),
   constraint check_distance check (km > 0)
);

In the previous query, what does the line constraint check_from_to check (from <> to), do exactly?

Thanks!


Solution

  • This is another version of the not equal operator:

    Not equal:
    mysql> SELECT '.01' <> '0.01';
           -> 1
    mysql> SELECT .01 <> '0.01';
           -> 0
    mysql> SELECT 'zapp' <> 'zappp';
           -> 1
    

    It's the same as using !=