Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I use NOT NULL a lot when creating columns.

Is there a way to make this default when defining columns? In other words, make column is_nullable default to NO. (I realize this would make it harder for me to set it to YES later one.)

share|improve this question

closed as unclear what you're asking by Mark Storey-Smith, Paul White, Kin, RolandoMySQLDBA, dezso Aug 4 '13 at 6:42

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

Are you asking how to save yourself from having to type 4 additional characters for each column definition? – Mark Storey-Smith Aug 3 '13 at 23:02
Changing the default behaviour of the CREATE TABLE and ALTER TABLE statements requires recompiling I think. Postgres is open source, so I guess you could do that. But the details would be a C question. – ypercubeᵀᴹ Aug 4 '13 at 7:20

YOU have to define NOT NULL when creating a table as described in documentation :

NOT NULL ==> The column is not allowed to contain null values.

Examples :

    code        char(5) CONSTRAINT firstkey PRIMARY KEY,
    title       varchar(40) NOT NULL,
    did         integer NOT NULL,
    date_prod   date,
    kind        varchar(10),
    len         interval hour to minute

Define two NOT NULL column constraints on the table distributors, one of which is explicitly given a name:

CREATE TABLE distributors (
    did     integer CONSTRAINT no_null NOT NULL,
    name    varchar(40) NOT NULL
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.