Two field primary key --> One field incremental

  • Hi,

    I want to create a key as shown in the Example below

    PK Col 1 PK Col 2 ......

    HCP000001 1

    HCP000001 2

    HCP000001 3

    HCP000001 4

    HCP000001 5

    HCP000002 1

    HCP000002 2

    HCP000002 3

    HCP000003 1

    Can I do this in the Insert (Col1,Col2,...) (SELECT (field1,field2....)

  • [font="Verdana"]You create keys as part of the table definition, not as part of an insert or select statement. Yes, it is perfectly valid to have a primary key across two fields.[/font]

  • my bad my question should have been whats he best way to increment the second column when inserting data to it.

    Ident is no good on the table design as I want the scenario where col1 value is new then col2 count gets reset back to 1

  • [font="Verdana"]Have a look at the row_number() function.[/font]

Viewing 4 posts - 1 through 3 (of 3 total)

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