Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CREATE TABLE example (
- col1 INT NOT NULL, -- null checkbox unchecked, no default
- col2 INT NULL, -- null checkbox checked, no default
- col3 INT NULL DEFAULT NULL, -- null checkbox checked, default null
- col4 INT NOT NULL DEFAULT 1 -- null checkbox unchecked, default value 1
- );
- INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, 1, 1); -- success
- INSERT INTO example(col1, col2, col3, col4) VALUES(NULL, 1, 1, 1); -- fails, col1 cannot be null
- INSERT INTO example(col1, col2, col3, col4) VALUES(1, NULL, 1, 1); -- success
- INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, NULL, 1); -- success
- INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, 1, NULL); -- fails, col4 cannot be null
- INSERT INTO example(col2, col3, col4) VALUES(1, 1, 1); -- fails, col1 has no default value
- INSERT INTO example(col1, col3, col4) VALUES(1, 1, 1); -- fails, col2 has no default value
- INSERT INTO example(col1, col2, col4) VALUES(1, 1, 1); -- success, col3 is set to NULL
- INSERT INTO example(col1, col2, col3) VALUES(1, 1, 1); -- success, col4 is set to 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement