The simplest way to create an autoincrement field in a table is to specifiy a default
of serial(x) with x being the integer where
you want your sequence to start. An example could look like this:
CREATE TABLE foo (
id INTEGER NOT NULL DEFAULT SERIAL(0),
content VARCHAR(100)
)
This would create a table called foo with an integer field id that increments by
itselft (almost). To make it increment
automatically an insert statement has to look like this:
INSERT INTO foo VALUES(0,'bar'). MaxDB will then automagically guess the next number
in the sequence.
Cheers
Uli
> -----Original Message-----
> From: H [mailto:[EMAIL PROTECTED]
> Sent: Friday, April 30, 2004 7:02 PM
> To: [EMAIL PROTECTED]
> Subject: Autoincrement field syntax in MAXDB
>
>
> I have the 2 questions pertaining to autoincrement fields.
>
> 1) MySql has an autoincrement field type but MAXDB seems not
> to? Is this true? I kinda thought that MySql and MaxDB had
> the same code-ancestry so why don't we have that feature in MAXDB?
>
> 2) If question 1 is true is the only way to get the
> autoincrement functionality in MaxDB is via a trigger and an
> sequence object... If this is true could someone please
> supply a simple working example. I used to code like this in
> Oracle but have long ago forgotten the syntax. I looked on
> the archive and found a thead of this discussion pasted below
> but the thread NEVER showed a working example.
>
> Thanks in advance,
>
>
> <<< Start of thread pertaining to Autoincrement field>>
> Scott, Niall wrote:
>
> > Hi
> >
> > I need to create a autoincrement field but I can't use a
> fixed data type
> for reasons I won't go into.
> > I need the field to be type integer.
> > I thought that I would create a sequence then call it in a
> trigger thus
> >
> > Create table test1(
> > teid integer,
> > aValue Char(10)
> > )
> > --
> > create sequence test1seq increment by 1 start with 1
> > --
> > CREATE TRIGGER test1_update FOR test1 AFTER INSERT EXECUTE (
> > UPDATE dbasys.test1 set teid=test1seq.Nextval;
> > )
> > --
> >
> > I tried various trigger code but the above was the only one
> that didn't
> give errors
> >
> > I then used
> > Insert into test1 (aValue) VALUES('Test 1')
> > but all I get is a null value in teid.
> >
> > I have come to SAP DB from Interbase where the trigger code would be
> > CREATE TRIGGER test1_update FOR TEST1
> > ACTIVE BEFORE INSERT POSITION 0
> > AS
> > BEGIN
> > new.teid=GEN_ID(test1seq,1);
> > END
> >
> >
> > But I can't figure out how to do the same in SAPDB
> >
> > Cheers
>
>
>
>
> ---------------------------------
> Post your free ad now! Yahoo! Canada Personals
>
--
MaxDB Discussion Mailing List
For list archives: http://lists.mysql.com/maxdb
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]