Re: CHECK constraint

2005-06-26 Thread Mathias
Hi, your enum canbe NULL and is not indexed. So you can insert values not in enum, replaced by NULL. a solution is to UNIQUE index the enum column, and insert a unique bad value in it. Any value not in enum can not then be inseted : mysql> create table enum_test(id int, name enum('test1','test2')

Re: CHECK constraint

2005-06-25 Thread Michael Kruckenberg
Hi, Use enum with a default type and let mysql do the check for you. The problem with an enum is that if you insert a value that's not in the enum, MySQL doesn't stop the insert, it leaves the column empty. This doesn't enforce data integrity like I think Chris wanted. mysql> desc enum_tes

Re: CHECK constraint

2005-06-25 Thread Mathias
Selon Michael Kruckenberg <[EMAIL PROTECTED]>: > A trigger is a good place to check the value, and change it, bit I > don't believe you can actually generate a MySQL error within the > trigger that will prevent the data from being inserted. Currently > (unless there's been an update to triggers th

Re: CHECK constraint

2005-06-25 Thread Rhino
ANTs don't permit any person or program to insert data directly via the table. Rhino - Original Message - From: "Partha Dutta" <[EMAIL PROTECTED]> To: "'Michael Kruckenberg'" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Cc: Sent: Saturday, J

RE: CHECK constraint

2005-06-25 Thread Partha Dutta
? www.mysql.com/certification > -Original Message- > From: Michael Kruckenberg [mailto:[EMAIL PROTECTED] > Sent: Saturday, June 25, 2005 10:57 AM > To: [EMAIL PROTECTED] > Cc: mysql@lists.mysql.com > Subject: Re: CHECK constraint > > A trigger is a good place to check t

Re: CHECK constraint

2005-06-25 Thread Michael Kruckenberg
A trigger is a good place to check the value, and change it, bit I don't believe you can actually generate a MySQL error within the trigger that will prevent the data from being inserted. Currently (unless there's been an update to triggers that's not yet in the docs), you can only change t

Re: CHECK constraint

2003-11-28 Thread Martijn Tonies
Hi, > I created a table as follows: > > mysql> CREATE TABLE test ( > -> age INT(3), > -> CONSTRAINT CHECK (age > 0) > -> ); > Query OK, 0 rows affected (0.00 sec) > > I then inserted -1 into the table, which it shouldn't > have let me do. > > mysql> insert into test values (-1); > Que