Skip to Content

Nested HDB Sequences

Hey guys, I am pretty new to db sql hdb and stuff. So let's say that in my db I have 3 entities. Contract, Item, Bill. Each Contract has an Item and each Item has a Bill. For this situation, as far as I know, it is recommended to use a sequence in order to generate the id and make sure it won't be a duplicate. My problem is if I should really use that or find another way because with sequence I have only 2 options (for the moment): 1. 1 sequence for Contract. For each contract, 1 sequence to count each Contract's Item and for each Item one sequence to count the Item's Bill. 2. Keep three sequences and every time I add a row, let's say I add an Item, I count how many items area already in the database and start the sequence from that number and increment it, which in my opinion cuts out all the charm of sequence (although I am very new to HDB and SQL and everything) Any suggestion is welcome. Thank you!

Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    Posted on Nov 01, 2019 at 05:53 PM

    hi Catalin, the first thing to understand the definition of a sequence.

    1) it is for the purpose of keeping unique ordered (unique numbered) list

    2) each sequence should be assigned to only one table

    in your example, you have 3 tables and therefore there should be 3 sequences. There shouldn't be any collision on your records since each will update independently from each other. Does that make sense? the sequences can all start w the same seed (1) or with whatever default value you assign on its definition AND they will increment based on the increment by property. Hope this makes sense

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.