Consider the following table:
CREATE TABLE user(
first_name text,
last_name text,
...
)
I would like to be able to add users with either a first name, a last name, or both - but I won't allow a user without any name. In other words (thanks, @wildplasser) - at least one column should not be NULL.
INSERT INTO user(first_name, last_name) VALUES ("foo", NULL); # 1. OK
INSERT INTO user(first_name, last_name) VALUES ("foo", "bar"); # 2. OK
INSERT INTO user(first_name, last_name) VALUES (NULL, "bar"); # 3. OK
INSERT INTO user(first_name, last_name) VALUES (NULL, NULL); # 4. NOT OK
Obviously, a NOT NULL
constraint on each columns would disable examples 2 and 3.
How can I express a NOT NULL
constraint on a set of columns in SQL?