Skip to main content

What happens if you don't specify all required fields in INSERT?

If INSERT doesn't provide values for required fields (i.e. columns with a NOT NULL constraint):

  1. An error occurs, the DBMS won't allow the record to be inserted.
  2. The record isn't added, the table's data stays unchanged.
  3. The error message usually points to exactly which field was violated.

Example:

sql
CREATE TABLE Employees ( ID INT PRIMARY KEY, Name VARCHAR(50) NOT NULL, Age INT ); -- An error, because the Name field is required INSERT INTO Employees (ID, Age) VALUES (1, 30);

Explanation:

  • Name has NOT NULL, so the database requires a value for that field.
  • To successfully insert the record, you need to either provide a value, or rely on a default value, if one is set via DEFAULT.

Put simply, required fields can't be left empty, otherwise SQL won't let the record be inserted.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.