Home > Back-end >  Declare all columns in a database to be NOT NULL by default?
Declare all columns in a database to be NOT NULL by default?

Time:04-19

Rather than littering my schema with NOT NULL almost everywhere I'd rather declare somewhere that all columns should be NOT NULL unless explicitly 'CAN BE NULL' or something.

Is there some way to do this? I'm using SQLite but curious for PostgreSQL also

CodePudding user response:

No, there are no databases that I know of that allow this. It would certainly be non-standard if they did.

CodePudding user response:

One of the dumbest things I ever saw in Microsoft SQL Server (yes, I know) were the two commands:

Not one, no, two separate commands. They read in part "Modifies the behavior of the session to override default nullability of new columns when the ANSI null default option for the database is false."

After finding these, I figured I could never assume anything about how SQL handled column default NULLability, and now I always set NULL/NOT NULL myself, no matter what RDBMS I use. (Back then I assumed this was an ANSII standard, and now I'm scarred for life.)

  • Related