MySQL Forums
Forum List  »  General

Create Table Constraint not Working on Update.
Posted by: Bob Carpenter
Date: June 10, 2018 11:51AM

I'm using mySQL version 5.6.39.

In the SQL below, when I do an update, I'm able to set status to foo, even though I added a constraint during table creation that's suppose to limit the values to either CONFIRMED or UNCONFIRMED.

Any ideas how to fix?

Thanks,

Bob


CREATE TABLE IF NOT EXISTS person (
pid varchar(16) UNIQUE NOT NULL,
firstname varchar(32) NOT NULL,
lastname varchar(32) NOT NULL,
password varchar(32) NOT NULL,
email varchar(64) UNIQUE NOT NULL,
status varchar(12) DEFAULT 'UNCONFIRMED',
datecreated timestamp DEFAULT CURRENT_TIMESTAMP,
datelastupdate timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (pid),
CONSTRAINT chk_status CHECK (status in('CONFIRMED','UNCONFIRMED'))
)
ENGINE=InnoDB AUTO_INCREMENT=14 DEFAULT CHARSET=latin1;

INSERT INTO person (pid, firstname, lastname, password, email) VALUES
('111AAA', 'Demo', 'User', '1Foobar7!', 'demo.user@foobar.com'),
('222BBB', 'Bob2', 'User', '1Foobar7!', 'bob2@foobar.com'),
('333CCC', 'Bob3', 'User', '1Foobar7!', 'bob3@foobar.com');

UPDATE person SET status = 'foo' WHERE pid = '111AAA';

SELECT * FROM person;

111AAA Demo User 1Foobar7! demo.user@foobar.com foo 2018-06-09 23:27:59 2018-06-09 23:28:15
222BBB Bob2 User 1Foobar7! bobc2@foobar.com UNCONFIRMED 2018-06-09 23:27:59 2018-06-09 23:27:59
333CCC Bob3 User 1Foobar7! bobc3@foobar.com UNCONFIRMED 2018-06-09 23:27:59 2018-06-09 23:27:59

Options: ReplyQuote


Subject
Written By
Posted
Create Table Constraint not Working on Update.
June 10, 2018 11:51AM


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.