[SQL] Unique constrain - Unerwartetes Verhalten bei NULL

Dieses Thema im Forum "Webentwicklung" wurde erstellt von wollknoll, 17. August 2010 .

Status des Themas:
Es sind keine weiteren Antworten möglich.
  1. 17. August 2010
    Unique constrain - Unerwartetes Verhalten bei NULL

    Hallo zusammen,

    ich habe folgende tabelle:

    Code:
    CREATE TABLE `test_table` (
    `id` INT NOT NULL ,
    `zahl1` INT NOT NULL ,
    `zahl2` INT NOT NULL ,
    `date` DATETIME NULL ,
    PRIMARY KEY ( `id` ) ,
    UNIQUE (`zahl1` ,`zahl2` ,`date`)
    );
    
    INSERT INTO `test_table` (`id` ,`zahl1` ,`zahl2` ,`date`)VALUES ('1', '1', '1', NULL);
    INSERT INTO `test_table` (`id` ,`zahl1` ,`zahl2` ,`date`)VALUES ('2', '1', '1', NULL);
    INSERT INTO `test_table` (`id` ,`zahl1` ,`zahl2` ,`date`)VALUES ('3', '1', '1', NULL);
    
    wieso greift der constrain nicht bei null, sondern nur wenn ich ein datum eingebe.
    Beispiel:

    Code:
    INSERT INTO `test_table` (`id` ,`zahl1` ,`zahl2` ,`date`)VALUES ('4', '1', '1', '2010-08-17 16:00:20');
    INSERT INTO `test_table` (`id` ,`zahl1` ,`zahl2` ,`date`)VALUES ('5', '1', '1', '2010-08-17 16:00:20');
    
    schonmal danke für die hilfe ...

    gruß
     
  2. 17. August 2010
    AW: Unique constrain problem

    dazu musst du "date" auf NOT NULL stellen, sonst wird das feld bei der uniq-prüfung ignoriert.
     
  3. 17. August 2010
    AW: Unique constrain - Unerwartetes Verhalten bei NULL

    hmm, das ist

    da ich ansonsten vorher abfragen muss, ob der eintrag überhaupt eingetragen werden darf.
    bzw. da fällt mir gerade ein das ich ja mit dem wert: '0000-00-00 00:00:00' anstatt null arbeiten kann.
     
  4. Video Script

    Videos zum Themenbereich

    * gefundene Videos auf YouTube, anhand der Überschrift.