mysql - do we have to explicitly mention the not null constraint for a primary key? -
do have explicitly mention primary key shouldn't null, when creating table? if don't mention 'not null' constraint primary key, sql wouldn't allow insert null value primary key field. therefore of following practice?
1) create table registration( id int primary key, name varchar(10) ) 2) create table registration( id int primary key not null, name varchar(10) )
no don't.
a primary key unique index key columns must defined not null. if not explicitly declared not null, mysql declares them implicitly (and silently). table can have 1 primary key. name of primary key primary, cannot used name other kind of index.
i'd consider practice state it explicitly - makes things more clear, , don't have rule every time you're in doubt.
Comments
Post a Comment