Distinct types allow the creation of user-defined data types that cannot be compared.

The following is the syntax for DB2

create distinct type person_id_type as integer with comparisons;
create distinct type address_id_type as integer with comparisons;

create table person 
(
  id     person_id_type not null primary key, 
  name   varchar(100)   not null
);

create table address
(
  id     address_id_type  not null primary key,
  info   varchar(100)     not null
);

The following join will then generate an error ("The data types of the operands for the operation "=" are not compatible or comparable"), because the type person_id_type cannot be compared to the type address_id_type.

select p.*
from person p
  join address a on a.id = p.id;

Back to the SQL Feature Comparison