IIRC mysql enforces referential integrity for primary keys. I don't think
it allows the column to have NULL values. I always try to use "int
unsigned auto_increment not null primary key" for my primaries unless they
are combinations of multiple columns and then it won't allow nulls as
well.
Curtis
On Thu, 8 May 2003, Brian Reichert wrote:
> On Thu, May 08, 2003 at 03:12:45AM -0700, Nitin Nanivadekar wrote:
> > 1. the max () keyword reports 'different' resultsets
> > when following queries are sent to it,
> > a. select max(id) from table1;
> > b. select max(id) from table1 where id2=100;
> > in any condition (like the low resources etc.) i
> > should not get different results from seemingly
> > identical queries.
>
> As you've described it, it's certainly possible; it completely
> depends on the table and it's contents.
>
> > 2. i will also point one observation when i was
> > hacking the max () function. when there is an empty
> > set max() reports Null.
>
> > this makes max() limited to
> > arithmatic ops only.
>
> I don't understand this assertion; MAX() works with strings as well.
>
> If stray NULL values are scaring you, try:
>
> select max(id) from mytable where id is not null;
>
> See <http://www.mysql.com/doc/en/Problems_with_NULL.html>
>
> Also consider using GREATEST().
>
> > i am using max() to find the next
> > incremental primary key index for some other table.
> > i am now seriously considering NOT using max() for
> > that reason after 1,. and 2. above.
>
> Why would you have NULL values in your incremental primary key index
> column? That (to me) implies a INT column, that should always have
> a value.
>
> > pls. comment.
> > -nitin
>
>
--
--
Curtis Maurand
mailto:curtis@stripped
http://www.maurand.com