I have just been learning SQL through http://www.w3schools.com/sql/, using XAMPP (I am also learning php).
Anyway, I try to run this query on the database, expecting an error because the entry violates the CHECK condition, but it goes through and I simply see the entry in the table which violates the CHECK -
INPUT:
- Code: Select all
CREATE TABLE OldPersons
(
Age INT(8) NOT NULL,
CONSTRAINT chk_Person CHECK (Age>200)
);
INSERT INTO OldPersons VALUES (34);
SELECT * FROM OldPersons;
OUTPUT:
- Code: Select all
Age
34
I've also tried using different ways of applying CHECK -
INPUT:
- Code: Select all
CREATE TABLE OldPersons
(
Age INT(8) NOT NULL,
CHECK (Age>200)
);
INSERT INTO OldPersons VALUES (34);
SELECT * FROM OldPersons;
and
INPUT:
- Code: Select all
CREATE TABLE OldPersons
(
Age INT(8) NOT NULL
);
ALTER TABLE OldPersons ADD CHECK (Age>200);
INSERT INTO OldPersons VALUES (34);
SELECT * FROM OldPersons;
and
INPUT
- Code: Select all
CREATE TABLE OldPersons
(
Age INT(8) NOT NULL
);
ALTER TABLE OldPersons ADD CONSTRAINT chk_Person CHECK (Age>200);
INSERT INTO OldPersons VALUES (34);
SELECT * FROM OldPersons;
and
INPUT:
- Code: Select all
CREATE TABLE OldPersons
(
Age INT(8) NOT NULL CHECK Age>200
);
INSERT INTO OldPersons VALUES (34);
SELECT * FROM OldPersons;
With this last one only supposed to work on SQL Server, Oracle, MS Access, but I tried it anyway. All of them gave the same output with the violating row going through. I find this really weird because PhpMyAdmin recognises the CHECK keyword in its syntax highlighting. See http://www.w3schools.com/sql/sql_check.asp
Please help!