Take the 2-minute tour ×
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. It's 100% free, no registration required.

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.

1  
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

1 Answer 1

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 :

CREATE TABLE films (
    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.