Re: Changing serial value
Posted in 1997
Here's how I see serial columns:
They're essentially not null integer columns with an added functionality
so that if you insert a zero value the actual value will be one more than
the highest value previously inserted. A table can have only one serial
column. Also, once a value is inserted it can't be changed with "update"
for some reason (tried it in online 7.21). However, the row can be
deleted and reinserted with a different serial value.
Yes, you can specify values of a serial column so you can "clone" tables.
Utilities like dbload and dbimport do this so that tables are recreated
exactly.
You can in fact insert duplicate values if there are no constraints to
oppose it. However, the whole purpose of a serial column is to
automatically provide unique values so they are normally set up as the
primary key or a unique key.
I was also surprised to find that if the serial column is ommitted in an
insert then a value is generated as if zero had been specified (as
opposed to null).
In article <33FF6AC7.2067@127.0.0.1>,
Mikey@NOSPAM.KingofMyDomain.MAPSON.Segel.com wrote:
>
> Dave Otto wrote:
> >
> > If you want to be able to control the value inserted, you need to
> > use a different data type. If you are just trying to clone a
> > record, exclude the "serial" column from the insert. You cannot
> > specify the value of a serial column.
> >
> > -d
> >
> Uhmm, sure you can.
> If you want Informix to set the serial valuse, insert the
> column with the serial value set to 0.
>
> If you insert a record with any other value (Not Null), you
> will be able to insert the record, if that value in the
> serial column is not used in the table, and it is greater that
> the current value held in the *serial counter* field. (An unsigned
> long somewhere in that table space.)
>
> HTH
>
> -Mikey
>
> Oh, and a caveat. I tested this with an old copy of SE.
> So it may or maynot be still true today. (Give it a whirl!)
>
> --
> #include <std_disclaimer.h> /* Mike Segel (MS385) */
> #include <No_Spam.h>
> #ifdef OFFENDED_BY_CONTENT
> The author takes no responsibility for this post.
> Any resemblence to a coherent rational thought is purely coincidence.
> -The Management.
> #endif
> *****************************
> Due to AGIS's Refusal to Act Responsibly
> We are blocking all of their domains at the packet level.
> This block will exist until AGIS modifies their policies to
> conform to existing RFCs and net community standards.
>
> We encourage all ISPs and domain holders to do the same.
> *****************************
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet