sql - How to make table not to take null values in not null set field in phpmyadmin? -
i have created 1 table in phpmyadmin not null set values still taking null values when inserting info using insert query. how solve this?
sql used create table:
create table exmp.student ( id int( 12 ) not null auto_increment primary key , name varchar( 200 ) not null , user_name varchar( 200 ) not null , branch varchar( 200 ) not null )
insert query:
insert exmp.student( name ) values ( 'harjeet' )
it's taking value table not showing error.
when run insert query, inserting empty strings user_name
, branch
columns. able replicate this.
if run query, explicitly setting non-null columns null, homecoming error:
insert student( name, user_name, branch ) values ( 'harjeet', null, null )
see mysql 5.0 reference data type default values:
as of mysql 5.0.2, if column definition includes no explicit default value, mysql determines default value follows:
if column can take null value, column defined explicit default null clause. same before 5.0.2.
if column cannot take null value, mysql defines column no explicit default clause. exception: if column defined part of primary key not explicitly not null, mysql creates not null column (because primary key columns must not null), assigns default clause using implicit default value. prevent this, include explicit not null in definition of primary key column.
for info entry not null column has no explicit default clause, if insert or replace statement includes no value column, or update statement sets column null, mysql handles column according sql mode in effect @ time:
if strict sql mode enabled, error occurs transactional tables , statement rolled back. nontransactional tables, error occurs, if happens sec or subsequent row of multiple-row statement, preceding rows have been inserted.
if strict mode not enabled, mysql sets column implicit default value column info type.
so looks mysql not have strict mode enabled. implicit default value varchar
column empty string, used. if want homecoming error, turn on string mode.
sql database database-design phpmyadmin
No comments:
Post a Comment