0% found this document useful (0 votes)
13 views15 pages

NOT NULL Constraint

The document discusses the NOT NULL constraint in SQL. It explains that NOT NULL means a field cannot be empty and will result in an error if left empty during insertion. An example table creation with a NOT NULL field is shown.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views15 pages

NOT NULL Constraint

The document discusses the NOT NULL constraint in SQL. It explains that NOT NULL means a field cannot be empty and will result in an error if left empty during insertion. An example table creation with a NOT NULL field is shown.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

NOT NULL Constraint

NOT NULL Constraint

primary key unique key

NULL VALUES no yes


NOT NULL Constraint

primary key unique key

NULL VALUES no yes

the “not null” restriction is applied through the NOT NULL Constraint
NOT NULL Constraint

primary key unique key

NULL VALUES no yes

the “not null” restriction is applied through the NOT NULL Constraint
- when you insert values in the table, you cannot leave the respective
field empty
NOT NULL Constraint

primary key unique key

NULL VALUES no yes

the “not null” restriction is applied through the NOT NULL Constraint
- when you insert values in the table, you cannot leave the respective
field empty
- if you leave it empty, MySQL will signal an error
ERROR
NOT NULL Constraint
NOT NULL Constraint

NOT NULL
NOT NULL Constraint

CREATE TABLE companies


(
company_id INT AUTO_INCREMENT,
headquarters_phone_number VARCHAR(255),
company_name VARCHAR(255),
PRIMARY KEY (company_id)
);
NOT NULL Constraint

CREATE TABLE companies


(
company_id INT AUTO_INCREMENT,
headquarters_phone_number VARCHAR(255),
company_name VARCHAR(255) NOT NULL,
PRIMARY KEY (company_id)
);
NOT NULL Constraint

Don’t confuse a NULL value with the value of 0 or with a


“NONE” response!

Think of a null value as a missing value.

0 NONE NULL

assigned by the assigned by the


user computer
NOT NULL Constraint

NULL
the value
of 0,
NOT NULL
NOT NULL Constraint

NULL
NOT NULL Constraint

NULL
NOT NULL Constraint

NULL
Next:
Coding Techniques and Best Practices
Data Manipulation

You might also like