MySQL Forums
Forum List  »  Spanish

Re: check como constraint
Posted by: Miguel Perez
Date: October 28, 2009 03:50AM

Porque no está implementado :)

Puedes hacer algo ligeramente parecido con vistas actualizables e insertables que comprueban las restricciones del WHERE (WITH CHECK OPTION).

Por ejemplo, imagina que queremos tener una tabla de rangos con columnas i, j con la aserción de que i <= j. Una forma de implementarlo es esta:
mysql:test> CREATE TABLE _Rangos (i INT, j INT, PRIMARY KEY (i, j));
Query OK, 0 rows affected (0.00 sec)

mysql:test> CREATE VIEW Rangos AS SELECT * FROM _Rangos WHERE i <= j WITH CHECK OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql:test> INSERT INTO Rangos VALUES (3, 5);
Query OK, 1 row affected (0.00 sec)

mysql:test> INSERT INTO Rangos VALUES (6, 5);
ERROR 1369 (HY000): CHECK OPTION failed 'test.Rangos'

Un saludo,

Miguel Pérez
Afina Sistemas - Partner de MySQL en España



Edited 1 time(s). Last edit at 10/28/2009 04:27AM by Miguel Perez.

Options: ReplyQuote


Subject
Views
Written By
Posted
1983
October 27, 2009 03:34PM
Re: check como constraint
2329
October 28, 2009 03:50AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.