[ale] newb mysql question: unique table serial #s

Jim Lynch ale_nospam at fayettedigital.com
Mon Mar 10 06:23:39 EDT 2008


Mike Harrison wrote:
> On Sun, 9 Mar 2008, Chris Woodfield wrote:
>
>   
>> I'm working on a perl script that talks to mysql for the first time,
>> and I'm coming up with all sorts of basic questions as to how to
>> structure the database table.
>>
>> One thing that my db will need is a sequential index/serial number, so
>> that records can be returned and sorted in sequence to their entry. I
>> know timestamps could do this, but I can't have duplicates.
>>     
>
> Almost all of my tables start with a generic field called 'uniq'
> which is a uniq ID number used in various generic recyclable functions
> for selecting just that record.
>
> An example:
>
> DROP TABLE IF EXISTS `stuff`;
> CREATE TABLE `stuff` (
>    `uniq` int(10) NOT NULL auto_increment,
>    `stuff` text default '',
>    `lastmod` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
>    PRIMARY KEY  (`uniq`),
>    UNIQUE KEY `id` (`uniq`)
> ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
>
>   
Unless you really know what you are doing, you don't want to insert a 
value into that field when doing inserts to the table.  It'll take care 
of itself.  E. g.
insert into stuff (stuff) values ('Hello World");

In Mike's example, the other two fields will be filled in automatically.

Jim.


More information about the Ale mailing list