At 09:36 PM 12/1/2001 -0700, Ashley M. Kirchner wrote:
>Bennett Haselton wrote:
>
> > Is it possible to set a column to have no possible default value, so if 
> you
> > try to create a record that doesn't specify a value for that column, 
> you'll
> > get an error?
>
>     Set it to NOT NULL

NOT NULL doesn't mean that the column doesn't have a default, it just means 
that the default is not null.  Then string columns get the default "", 
numeric columns get the default "0", date columns get the default 
"0000-00-00", etc.

I want a column where you get an error if you try to create a record 
without specifying a value for that column.  Can it be done?

> > For example, if I have a table where the "date" field should always be
> > set.  I took out the default "NULL" value, but that just gave it a 
> default
> > value of 0000-00-00.  What I want to ensure is that it's not possible 
> to
> > create a record for which the date value hasn't been specified.
>
>     Who's going to stop a user from entering 0000-00-00?  You'll have to 
> create validation schemes in your code.

I'm mainly talking about "validation" in places where I might try, *in* the 
code, to create a new record and forget to specify the date value.  The 
database that I'm writing won't have "end users" as such, it's just used 
from many different places in code, and when you're writing something 
that's used by many different code snippets, it can be advantageous to 
write it in such a way to reduce the likelihood of errors in any of those 
snippets.  Hence, the idea of a column marked such that MySQL gives an 
error if you don't set it.

         -Bennett

[EMAIL PROTECTED]     http://www.peacefire.org
(425) 649 9024


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to