Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Datenbanken (https://www.delphipraxis.net/15-datenbanken/)
-   -   Delphi Problem mit "NOT NULL - Feld" (https://www.delphipraxis.net/69122-problem-mit-not-null-feld.html)

Kedariodakon 10. Mai 2006 23:46

Re: Problem mit "NOT NULL - Feld"
 
hmm das weiß ich nicht, teste es doch einfach :wink:
Reponse wär dann nicht schlecht, falls mal wer ein ähnliches Problem hat...

Bye Keda

Hansa 10. Mai 2006 23:58

Re: Problem mit "NOT NULL - Feld"
 
So ungefähr geht das :

http://www.ibexpert.info/documentati...raint/738.html

Angel4585 11. Mai 2006 05:04

Re: Problem mit "NOT NULL - Feld"
 
Also ich habe jetzt mit INSERT was eingefügt was durchb das CHECK eigentlich ausgeschlossen werden sollte und es wurde trotzdem in die Tabelle geschrieben. Muss ich das anders reinschreiben oder funktioniert das vllt einfach nur nicht mit MySQL?

Hansa dein Beispiel bezieht sich ja auf Firebird aber was ist mit MySQL?

mkinzler 11. Mai 2006 05:22

Re: Problem mit "NOT NULL - Feld"
 
Ich glaube die Firma MySql hat auch ne Homepage, auf der sie ihren Systax erklären.

Angel4585 12. Mai 2006 07:11

Re: Problem mit "NOT NULL - Feld"
 
Zitat:

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.



Alle Zeitangaben in WEZ +1. Es ist jetzt 14:59 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz