Friday, February 7, 2020

NULL and NOT NULL

NULL and NOT NULL Code

Try inserting a cat without an age:
INSERT INTO cats(name) VALUES('Alabama'); 
SELECT * FROM cats; 
Try inserting a nameless and ageless cat:
INSERT INTO cats() VALUES(); 
Define a new cats2 table with NOT NULL constraints:

DESC cats2; 
Now try inserting an ageless cat:
INSERT INTO cats2(name) VALUES('Texas'); 
View the new warnings:
SHOW WARNINGS; 
SELECT * FROM cats2; 
Do the same for a nameless cat:
INSERT INTO cats2(age) VALUES(7); 
SHOW WARNINGS; 

No comments:

Post a Comment

Right Joins

-- OUR FIRST RIGHT JOIN (seems the same as a left join?) SELECT * FROM customers RIGHT JOIN orders     ON customers.id = orders.custom...