I started learning SQL (SQL-Server) a few days ago but now I'm getting confused about when is it necessary to set NOT NULL for a field. I've known that the NOT NULL restriction won't let me update that row after it was created with null value. But how we know whether a field of data worth setting NOT NULL or not?
Considering the following example (Extracted from the internet):
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25),
SALARY INT
PRIMARY KEY (ID)
);
Why ID, Name, Age are set NOT NULL whereas ADRESS, SALARY are not. Is setting-NOT-NULL-restriction for fields at my disposal?
If I set NOT NULL restriction for all the fields of the table as the following. Is it ok?
CREATE TABLE CUSTOMERS(
ID INT NOT NULL,
NAME VARCHAR (20) NOT NULL,
AGE INT NOT NULL,
ADDRESS CHAR (25) NOT NULL,
SALARY INT NOT NULL
PRIMARY KEY (ID)
);
Hope to receive any explaination about my problem. Thanks in advance!