Post
#1
|
|
|
Grupa: Zarejestrowani Postów: 1 590 Pomógł: 185 Dołączył: 19.04.2006 Skąd: Gdańsk Ostrzeżenie: (0%)
|
Witajcie, mam (nie wiem czy nie głupi) problem - mam w bazie pole "xyz" i chcę, aby dane w nim zawarte (powiedzmy numer aneksu umowy) były unikalne - dodałem indeks UNIQUE i niby jest ok, ale co zrobić, gdy pole "xyz" nie jest wymagane i może być puste? W momemncie dodawania drugiego pustego rekordu pojawia się "duplicate entry...". Da się jakoś prosto temu zaradzić? Ustawić unikalność tylko dla niepustych?
|
|
|
|
![]() |
Post
#2
|
|
|
Grupa: Przyjaciele php.pl Postów: 5 724 Pomógł: 259 Dołączył: 13.04.2004 Skąd: N/A Ostrzeżenie: (0%)
|
nospor - e-e, pozwoli wrzucic tylko JEDNEGO null'a, Pilsner - BEFORE INSERT TRIGGERA dodaj ktory sprawdzi i odrzuci rekord ze zduplikowana wartoscia
edit: eh (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) a jednak UNIQUE zadziala w mysql Cytat UNIQUE index creates a constraint such that all values in the index must be distinct. An error occurs if you try to add a new row with a key value that matches an existing row. This constraint does not apply to NULL values except for the BDB storage engine. For other engines, a UNIQUE index allows multiple NULL values for columns that can contain NULL. http://dev.mysql.com/doc/refman/5.0/en/create-index.html Ten post edytował dr_bonzo 15.09.2008, 11:18:06 |
|
|
|
Pilsener UNIQUE dla niepustych rekordów 15.09.2008, 11:06:23
nospor puste pola ustawiaj jako NULL a nie jako pusty str... 15.09.2008, 11:07:58 
Pilsener Cytat(nospor @ 15.09.2008, 10:07:58 )... 15.09.2008, 12:22:02
nospor Cytatnospor - e-e, pozwoli wrzucic tylko JEDNEGO n... 15.09.2008, 11:27:45
dr_bonzo Z PG:
CytatWhen an index is declared unique, mult... 15.09.2008, 13:02:21 ![]() ![]() |
|
Aktualny czas: 13.03.2026 - 10:13 |