When writing DDL in SQL, you can specify a couple of constraints on columns, like NOT NULL or DEFAULT constraints. Some people might wonder, if the two constraints are actually redundant, i.e. is it still necessary to specify a NOT NULL constraint, if there is already a DEFAULT clause? The answer is: Yes! Yes, you … Continue reading Have You Ever Wondered About the Difference Between NOT NULL and DEFAULT?
A lesser-known SQL feature is the DEFAULT keyword, which can be used in INSERT and UPDATE statements. Consider the following table, created using standard SQL syntax: CREATE TABLE timestamps ( id INTEGER GENERATED BY DEFAULT AS IDENTITY(START WITH 1), t TIMESTAMP DEFAULT CURRENT_TIMESTAMP, CONSTRAINT pk_values PRIMARY KEY (id) ) Now, in order to generate a … Continue reading Lesser-Known SQL Features: DEFAULT VALUES