0

I have a table

    id int
    sub_id int
    name varchar

Example:

id, sub_id, name
1, 1, USA
1, 2, Germany 
1, 3, Russia
2, 1, English
2, 2, German
2, 3, Russian

Let's say user enter 3 for id, so sub_id should be 1, 2, 3... if user will enter 4, sub_id count should start from 1. Is it possible to autoincrement sub_id?

CL.
  • 173,858
  • 17
  • 217
  • 259
axzu fs
  • 63
  • 1
  • 1
  • 5
  • what is `sub_id`? Does it act like a sequencer or is it a self reference: `German is spoken in Germany`? – Ňɏssa Pøngjǣrdenlarp Jul 08 '16 at 17:58
  • 1
    SQL provides automatically incrementing fields, as in the marked duplicate. If you have some specific question about using that, please fix your question so that it explains clearly what you already know and what _specifically_ you're having trouble with. Also, if your question does not involve C# programming (it appears not to), then remove the [tag:c#] tag from your question. If it does involve C# programming, please explain how. – Peter Duniho Jul 08 '16 at 18:01
  • 2
    @PeterDuniho, that's a wrong match. OP is definitely not asking for `IDENTITY`. Looks like you misinterpreted the question. Voting to reopen it. – Rahul Jul 08 '16 at 18:01
  • it is also tagged as SQLite not SqlServer – Ňɏssa Pøngjǣrdenlarp Jul 08 '16 at 18:08
  • @PeterDuniho please read my post. I'm using c#, SQL, SQLite. Maybe it can be done through c#, that's why I tagged c#. Please open... – axzu fs Jul 08 '16 at 18:25
  • @PeterDuniho definitely not the same question as the duplicate you tagged! This individual wants an second identity column that resets every x # of rows based on values on another row and column! – Matt Jul 08 '16 at 18:40
  • @axzufs iookup up the equivalent of ROW_NUMBER window functions for sqllite. If you just want to generate on the fly you will be able to write the query. If you want to store it in the database it will require an extra update statement based on the results. – Matt Jul 08 '16 at 18:47

0 Answers0