List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:December 13 2001 4:25am
Subject:Re: NOT NULL field accepting NULL
View as plain text  
On Thu, Dec 13, 2001 at 09:50:11AM +0530, sreedhar wrote:
> Hello,
> 
> CREATE TABLE tblTEST(field1 VARCHAR(20) NOT NULL, field2 VARCHAR(20) NOT
> NULL);
> 
> INSERT INTO tblTEST (field1) VALUES (NULL);
> INSERT INTO tblTEST (field2) VALUES (NULL);
> INSERT INTO tblTEST (field1,field2) VALUES (NULL,'HELLO');
> 
> not accepting NULL  values; but
> 
> INSERT INTO tblTEST (field1) VALUES ('HELLO');
> 
> This statement inserting empty value in 'field2'.
> 
> field1         field2
> HELLO
> 
> so how can we make INSERT statement to fail if value of NOT NULL field is
> not supplied.

You don't.
MySQL supplies a default value for any field that isn't specified.
You should verify that you have a value for field1 before issuing
the insert.  You'd have to handle an error anyway.

> 
> thanks
> 
> regards,
> sreedhar
> 
> 
> ----- Original Message -----
> From: "Paul DuBois" <paul@stripped>
> To: "sreedhar" <sreedhar@stripped>; "mysql"
> <mysql@stripped>
> Sent: Wednesday, December 12, 2001 11:25 PM
> Subject: Re: NOT NULL field accepting NULL
> 
> 
> > At 7:12 PM +0530 12/12/01, sreedhar wrote:
> > >Hi All,
> > >
> > >In MySQL, Even i declared a field as NOT NULL it is accepting nulls .What
> > >might be the
> > >problem. please let me know.
> > >
> > >regards,
> > >sreedhar
> >
> > That's not enough information.
> >
> > Let's see the CREATE TABLE statement, a sample INSERT statement, and
> > the resulting record.
Thread
NOT NULL field accepting NULLsreedhar12 Dec
  • Re: NOT NULL field accepting NULLPaul DuBois12 Dec
    • tunning up my sqlHernan Del Boca12 Dec
  • Re: NOT NULL field accepting NULLsherzodR12 Dec
  • Re: NOT NULL field accepting NULLsreedhar13 Dec
    • Re: NOT NULL field accepting NULLPaul DuBois13 Dec