Solved

Interbase sequences

Posted on 2001-08-07
6
335 Views
Last Modified: 2008-02-26
Does anyone know if interbase supports the concept of sequences? If not what is the best way to generate an integer primary key?

Thanks

J
0
Comment
Question by:nnbbb09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
6 Comments
 
LVL 27

Accepted Solution

by:
kretzschmar earned 75 total points
ID: 6362713
the sequences known by oracle are called generators in interbase

to create a generator

create generator Aname;

to access the generator

gen_id(AName)

meikl ;-)
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6362741
a sample for an insert

insert into atable (id, afield) values (gen_id(aname), 'Something')
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6362753
see also
http://community.borland.com/article/0,1410,25167,00.html

i have missed somethig
to access use

gen_id(aname,1)

meikl ;-)
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 6362759
or

Auto-Increment fields in InterBase - by Borland Developer Support Staff




Abstract:How to create an Auto-Increment field in InterBase
Question:
    I have an InterBase table, but I can?t figure out how to make an Auto-Increment field for it. How do I do this?
Answer:
    InterBase doesn?t have a convenient AutoInc datatype like Paradox, so we have to do a little bit of work to get this functionality. Start out by creating an Integer field that is appropriate for the size of the values you want in your AutoInc field. From there, we need a trigger to calculate the value for the field:


     CREATE TRIGGER autoinc FOR tablename
     BEFORE INSERT AS
     BEGIN
        NEW.autoinc_field_nane = GEN_ID(generator_name, 1);
     END

    We aren?t done yet. We need a persistent location to store the current AutoInc value. InterBase?s way to deal with this is called a generator:

     CREATE GENERATOR generator_name;
     SET GENERATOR generator_name TO x;

    GEN_ID() is a built-in InterBase function specially designed to increment the generator specified by the first parameter by the value in the second parameter. The SET GENERATOR statement initializes the generator to the value provided by x. This is useful if your database is based on something like a customer number, and you want this customer number to start at a specific value rather than zero.     And that is all there is to it. From here on, you can insert away and this trigger will stick the correct value into autoinc_field_name. For further information on how to work with Auto-Increment fields in your application, read the TI "Working With Auto-increment Field Types" at http://community.borland.com/article/0,1410,16123,00.html.
0
 
LVL 3

Author Comment

by:nnbbb09
ID: 6362879
Thanks Meikl. I'm new to Interbase so I may have a few more questions in the future!

Jo
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6362957
no problem i use a lot different databases,
except they from microsoft,
primary oracle, but also interbase

just ask, if you have a problem

well, glad to helped you in this case :-)
good luck again

meikl ;-)


0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
As technology users and professionals, we’re always learning. Our universal interest in advancing our knowledge of the trade is unmatched by most industries. It’s a curiosity that makes sense, given the climate of change. Within that, there lies a…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question