GirişUnique kısıtı create table esnasında veya daha sonra alter table ile eklenebilir.
Örnek
ALTER TABLE table ADD CONSTRAINT "abc123" UNIQUE ("col1", "col2");
Unique Sütun Null Değer Almamalı
Açıklaması
şöyle. Çünkü Null unknown yani bilinmeyen değeri temsil eder. İki tane unknown ise birbiriyle karşılaştırılamaz.
In general, a unique constraint is violated if there is more than one row in the table where the values of all of the columns included in the constraint are equal. However, two null values are never considered equal in this comparison. That means even in the presence of a unique constraint it is possible to store duplicate rows that contain a null value in at least one of the constrained columns. This behavior conforms to the SQL standard, but we have heard that other SQL databases might not follow this rule. So be careful when developing applications that are intended to be portable.
Örnek
Elimizde şöyle bir constraint
olsun. Yani tüm sütunları kısıta dahil edelim.
ALTER TABLE table ADD CONSTRAINT "abc123" UNIQUE
("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8");
Aynı değere sahip iki tane satırı ekleyebildiğimizi
görürüzINSERT INTO table ("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8")
VALUES ('a', 'b', 'c', 'd', 'e', 'f', null, true);
INSERT INTO table ("col1", "col2", "col3", "col4", "col5", "col6", "col7", "col8")
VALUES ('a', 'b', 'c', 'd', 'e', 'f', null, true);