Question about a composite key and autoincrement

  • ScottPletcher - Monday, February 26, 2018 5:00 PM

    Does is really matter if the numbers are sequential or is everyone just used to that?

    If it doesn't really matter, you might just use an identity column and let each row get the next number.

    If you really needed a sequential number for display reasons in certain output, you could use ROW_NUMBER() to derive that.

    Actually, sequences can required by law. In Italy, invoice numbers and some other things have to be sequential.

    Please post DDL and follow ANSI/ISO standards when asking for help. 

  • jcelko212 32090 - Tuesday, February 27, 2018 10:58 AM

    ScottPletcher - Monday, February 26, 2018 5:00 PM

    Does is really matter if the numbers are sequential or is everyone just used to that?

    If it doesn't really matter, you might just use an identity column and let each row get the next number.

    If you really needed a sequential number for display reasons in certain output, you could use ROW_NUMBER() to derive that.

    Actually, sequences can required by law. In Italy, invoice numbers and some other things have to be sequential.

    Hence the IF it doesn't matter.  And if you want absolutely sequential numbers, sequences probably aren't the best answer anyway.

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • jcelko212 32090 - Tuesday, February 27, 2018 10:58 AM

    ScottPletcher - Monday, February 26, 2018 5:00 PM

    Does is really matter if the numbers are sequential or is everyone just used to that?

    If it doesn't really matter, you might just use an identity column and let each row get the next number.

    If you really needed a sequential number for display reasons in certain output, you could use ROW_NUMBER() to derive that.

    Actually, sequences can required by law. In Italy, invoice numbers and some other things have to be sequential.

    If that really is the case, then a SEQUENCE is completely out, since it will have gaps in it.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 3 posts - 16 through 17 (of 17 total)

You must be logged in to reply to this topic. Login to reply