locked
Auto increment in asp.net RRS feed

  • Question

  • Hi,

    I am making a Windows Form Application and i have to do auto increment (Like 1,2,3,4.......) in my column without using Identity column.So some one knows the ans then please help me...

    I want to do in SQL query or C# coding.

    Saturday, April 20, 2013 5:58 AM

Answers

  • is there any particular reason you do not want to use identity(1,1),, If the reason is that you have to return the Identity value to the application, you can insert into the table and return the identity value for that session to application..

    I do not know how consistent/effective will the code generated auto increments will be? will be good to know though..sorry could not help..


    Hope it Helps!!

    Saturday, April 20, 2013 6:52 AM
  • An alternative to IDENTITY is a SEQUENCE.  But, like Stan, I would like to know why you don't want to use an identity.  Perhaps we can offer a better alternative to meet your needs.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, April 20, 2013 12:51 PM
    Answerer

All replies

  • is there any particular reason you do not want to use identity(1,1),, If the reason is that you have to return the Identity value to the application, you can insert into the table and return the identity value for that session to application..

    I do not know how consistent/effective will the code generated auto increments will be? will be good to know though..sorry could not help..


    Hope it Helps!!

    Saturday, April 20, 2013 6:52 AM
  • An alternative to IDENTITY is a SEQUENCE.  But, like Stan, I would like to know why you don't want to use an identity.  Perhaps we can offer a better alternative to meet your needs.


    Dan Guzman, SQL Server MVP, http://www.dbdelta.com

    Saturday, April 20, 2013 12:51 PM
    Answerer
  • is there any particular reason you do not want to use identity(1,1),, If the reason is that you have to return the Identity value to the application, you can insert into the table and return the identity value for that session to application..

    I do not know how consistent/effective will the code generated auto increments will be? will be good to know though..sorry could not help..


    Hope it Helps!!


    Thank you Stan and Dan for your help in this forum! Please email me at edprice at Microsoft. Thanks!

    Ed Price (a.k.a User Ed), SQL Server Customer Program Manager (Blog, Small Basic, Wiki Ninjas, Wiki)

    Answer an interesting question? Create a wiki article about it!

    Monday, April 22, 2013 10:22 PM
  • You can generate the sequence yourself:

    SELECT NextID = MAX(ID)+1 FROM YOURTABLE


    Kalman Toth Database & OLAP Architect sqlusa.com
    New Book / Kindle: Pass SQL Exam 70-461 & Job Interview: Programming SQL Server 2012

    Tuesday, April 23, 2013 12:28 AM