AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Datenbanken Delphi Problem mit "NOT NULL - Feld"
Thema durchsuchen
Ansicht
Themen-Optionen

Problem mit "NOT NULL - Feld"

Ein Thema von Angel4585 · begonnen am 10. Mai 2006 · letzter Beitrag vom 12. Mai 2006
Antwort Antwort
Angel4585

Registriert seit: 4. Okt 2005
Ort: i.d.N.v. Freiburg im Breisgau
2.199 Beiträge
 
Delphi 2010 Professional
 
#1

Re: Problem mit "NOT NULL - Feld"

  Alt 12. Mai 2006, 08:11
Zitat von Bill K. von MySQL.com:
MySQL accepts CHECK constraint syntax in the CREATE TABLE statement, and gives no error. But MySQL does not store any information for the constraint, and does not enforce the constraint.

Similarly for foreign key constraints when using MyISAM tables.

IMHO, this is a bad decision on the part of the makers of MySQL. They did it so that users could import schema definitions from other RDBMS that make use of these features, without editing their DDL scripts. But it causes users to have a false impression that a given constraint has been defined in the schema.

As an alternative, if you use MySQL 5.0 you can write a trigger that changes your Field1 to NULL if someone attempts to insert a value of "". That way, the NOT NULL constraint on that column will be violated and the operation will be aborted.

CREATE TRIGGER noblank_field1 BEFORE INSERT ON Tablename
FOR EACH ROW BEGIN
IF NEW.Field1 = "" THEN
SET NEW.Field1 = NULL;
END IF;
END

(Also make a similar trigger BEFORE UPDATE.)

If you use a version of MySQL earlier than 5.0, triggers are not implemented. You would have to enforce the rule in application code.

--
Regards,
Bill K.
Martin Weber
Ich bin ein Rüsselmops
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:37 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz