I'm doing my first database project.

I must know why you need to use NOT NULL within the following query

...
TITLE nvarchar(60) NOT NULL
..

Context

CREATE TABLE Questions 
(
         USER_ID integer FOREIGN KEY 
                         REFERENCES User_info(USER_ID) 
                         PRIMARY KEY 
                         CHECK (USER_ID>0), 
         QUESTION_ID integer FOREIGN KEY REFERENCES Tags(QUESTION_ID) 
                             NOT NULL 
                             CHECK (USER_ID>0), 
         QUESTION_BODY nvarchar(4000) NOT NULL,
         TITLE nvarchar(60) NOT NULL,                               /////// HERE                             
         MODERATOR_REMOVAL boolean NOT NULL,
         SENT_TIME varchar(15) NOT NULL
)

I viewed VPuml's tutorial. Installed all values in Logical diagram nullable, while all of the relaxation NOT NULL. This indicates me that nullable ought to be combined with logical diagrams.

Can there be every other utilization of not null in databases?

Personally i think that people can make sure that the consumer gives value by JS, for example, not in a database level.

If your null value isn't permitted, you can examine on user entry and haven't NULL within the database. Getting NOT NULL within the database enables you to definitely make certain that no damaging information is joined in to the database, no matter mistakes in-front-finish code.

However, since database errors are usually bad to exhibit your customers, you can examine to make certain that the null value isn't being posted before it reaches the database check.

NOT NULL is frequently employed for foreign secrets (i.e.-links with other tables). It guarantees that the row links with a other table.

It will always be utilized on primary secrets, meaning the initial identifier within the table.

It is also an excellent constraint for needed fields. This guarantees the transaction will fail if your user does not type in a title or perhaps a question. Databases are wonderful at enforcing constraints such as this very rapidly, this is why lots of that kind of business logic put in databases. Do note, however, that you will want to look into the database error around the application side and take care of it accordingly.

Anyway, NOT NULL is actually for any column you always desire a value in. The instances for your are really a number of, but hopefully this provides you some semblance of why it's used by us.

NOT NULL implies that something should be put into the column. It's used if this will not make any sense for that data to exist with no value.

For example, inside your "SO" database, it can make no sense for any question to exist with no user_id column being known. An issue must probably always will be produced with a user.

From time to time, a question is dependent on whether a particular area includes a value. Getting the area be NOT NULL means you just check against just one empty value, within this situation '' (the empty string). Permitting NULL values means you might want to check for your, too, which could complicate the query.