MySQL Forums
Forum List  »  InnoDB

Q) Integrity Constraint using CHECK in a CREATE query.
Posted by: Bruce Oh
Date: November 24, 2009 01:45AM

Hi all,

I've tried with an Integrity Constraint using CHECK in a CREATE query.

mySql honored the query, but I didn't see any constraint checking by mySQL 5.1.

Please see the query sequence below.

Thank you.




====below====

mysql> CREATE TABLE Account3 (
-> CreditCardNo VARCHAR(16) PRIMARY KEY,
-> ExpirationDate VARCHAR(6) NOT NULL,
-> Status CHAR(1) NOT NULL,
-> CHECK (
-> NOT EXISTS (
-> SELECT *
-> FROM Account3
-> WHERE ExpirationDate='092011'
-> )
-> )
-> );
Query OK, 0 rows affected (0.13 sec)

mysql>
mysql> INSERT INTO Account3 VALUES ('5444444444444444', '082010', 'A');
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO Account3 VALUES ('4555555555555555', '092010', 'A');
Query OK, 1 row affected (0.03 sec)

mysql> INSERT INTO Account3 VALUES ('4666666666666666', '092011', 'A');
Query OK, 1 row affected (0.16 sec)

mysql> INSERT INTO Account3 VALUES ('4777777777777777', '092011', 'A');
Query OK, 1 row affected (0.05 sec)

mysql> SELECT *
-> FROM Account3
-> WHERE ExpirationDate='092011';
+------------------+----------------+--------+
| CreditCardNo | ExpirationDate | Status |
+------------------+----------------+--------+
| 4666666666666666 | 092011 | A |
| 4777777777777777 | 092011 | A | <=========
+------------------+----------------+--------+
2 rows in set (0.00 sec)

Options: ReplyQuote


Subject
Views
Written By
Posted
Q) Integrity Constraint using CHECK in a CREATE query.
6679
November 24, 2009 01:45AM


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.