ako sam uspeo da dekodiram tu cudnu terminologiju koju vidim prvi put (obelezje je kljuc ili polje?) jedini nacin da odradis testiranje vrednosti unutar tabele je trigerom (na insert i na update proveris da li se vrednosti poklapaju sa pravilima koja imas)
http://stackoverflow.com/quest...nsert-under-certain-conditions
e sad ako koristis
mysql 5.5 onda mozes da koristis
signal dakle nesto ovako:
Code:
mysql> drop table t1;
Query OK, 0 rows affected (0.00 sec)
mysql> CREATE TABLE `t1` (
-> `f1` int primary key auto_increment not null,
-> `f2` int DEFAULT NULL,
-> `f3` int DEFAULT NULL
-> ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.03 sec)
mysql>
mysql> drop trigger tt;
ERROR 1360 (HY000): Trigger does not exist
mysql>
mysql> delimiter $$
mysql> CREATE
-> TRIGGER `tt`
-> BEFORE INSERT ON `t1`
-> FOR EACH ROW
-> begin
-> declare mystate condition for sqlstate '7CL02';
-> if New.f3 > New.f2 then
-> SIGNAL SQLSTATE '55555';
-> end if;
-> end
-> $$
Query OK, 0 rows affected (0.00 sec)
mysql>
mysql> delimiter ;
mysql>
mysql> insert into t1 values (1,1,1), (2,2,2), (3,3,3), (4,4,5), (5,5,4);
ERROR 1644 (55555): Unhandled user-defined exception condition
mysql> select * from t1;
Empty set (0.00 sec)
mysql>
mysql> insert into t1 values (1,1,1);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values (2,2,2);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values (3,3,3);
Query OK, 1 row affected (0.00 sec)
mysql> insert into t1 values (4,4,5);
ERROR 1644 (55555): Unhandled user-defined exception condition
mysql> insert into t1 values (5,5,4);
Query OK, 1 row affected (0.00 sec)
mysql>
mysql> select * from t1;
+----+------+------+
| f1 | f2 | f3 |
+----+------+------+
| 1 | 1 | 1 |
| 2 | 2 | 2 |
| 3 | 3 | 3 |
| 5 | 5 | 4 |
+----+------+------+
4 rows in set (0.00 sec)