Advertisement
Guest User

Untitled

a guest
Jul 21st, 2016
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.07 KB | None | 0 0
  1. CREATE TABLE example (
  2.   col1 INT NOT NULL,          -- null checkbox unchecked, no default
  3.   col2 INT NULL,              -- null checkbox checked, no default
  4.   col3 INT NULL DEFAULT NULL, -- null checkbox checked, default null
  5.   col4 INT NOT NULL DEFAULT 1 -- null checkbox unchecked, default value 1
  6. );
  7.  
  8. INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, 1, 1); -- success
  9. INSERT INTO example(col1, col2, col3, col4) VALUES(NULL, 1, 1, 1); -- fails, col1 cannot be null
  10. INSERT INTO example(col1, col2, col3, col4) VALUES(1, NULL, 1, 1); -- success
  11. INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, NULL, 1); -- success
  12. INSERT INTO example(col1, col2, col3, col4) VALUES(1, 1, 1, NULL); -- fails, col4 cannot be null
  13. INSERT INTO example(col2, col3, col4) VALUES(1, 1, 1); -- fails, col1 has no default value
  14. INSERT INTO example(col1, col3, col4) VALUES(1, 1, 1); -- fails, col2 has no default value
  15. INSERT INTO example(col1, col2, col4) VALUES(1, 1, 1); -- success, col3 is set to NULL
  16. 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