List:General Discussion« Previous MessageNext Message »
From:Martijn Tonies Date:April 14 2004 3:39pm
Subject:Re: NOT NULL column behaves strangely
View as plain text  
Hi,

> Why does MySQL accept this insert statement with a warning?
>
> Insert into Sessions (id) values (20de8376640263673ea03938);
>
> Query OK, 1 row affected.
>
> I expected a warning because of the Token column shouldn't be NULL!
>
> I have a table with three columns:
>
> Id # int not null
> Token # char (1) not null
> SessTime # Timestamp

Welcome to the wonderful world of MySQL ;-)

Read this:
http://dev.mysql.com/doc/mysql/en/CREATE_TABLE.html

" DEFAULT value must be a constant; it cannot be a function or an
expression. If no DEFAULT value is specified for a column, MySQL
automatically assigns one, as follows. If the column can take NULL as a
value, the default value is NULL. If the column is declared as NOT NULL, the
default value depends on the column type:
  a.. For numeric types other than those declared with the AUTO_INCREMENT
attribute, the default is 0. For an AUTO_INCREMENT column, the default value
is the next value in the sequence.
  b.. For date and time types other than TIMESTAMP, the default is the
appropriate ``zero'' value for the type. For the first TIMESTAMP column in a
table, the default value is the current date and time. See section 12.5 Date
and Time Types.
  c.. For string types other than ENUM, the default value is the empty
string. For ENUM, the default is the first enumeration value. "

With regards,

Martijn Tonies
Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL
Server.
Upscene Productions
http://www.upscene.com

Thread
NOT NULL column behaves strangelyB. Fongo14 Apr
  • Re: NOT NULL column behaves strangelyKeith C. Ivey14 Apr
    • Re: NOT NULL column behaves strangelyRuslan U. Zakirov14 Apr
      • Re: NOT NULL column behaves strangelyMichael Stassen14 Apr
        • AW: NOT NULL column behaves strangelyB. Fongo14 Apr
  • Re: NOT NULL column behaves strangelyMartijn Tonies14 Apr
    • AW: NOT NULL column behaves strangelyB. Fongo14 Apr