To Generate serial number automatically

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeenajos
    New Member
    • Oct 2007
    • 71

    To Generate serial number automatically

    Hi all,
    I need to insert a column in a table as sno but it should generated numbers from 1,2,3,.....It is similar to ms excel's auto number.Tel me a way to do it in SQL Express.

    Cheers
    Jeen
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Try this:


    Code:
    Alter your_table_name add ID int identity(1,1)
    When you issue insert statement omit mentioning this column and number will be generated automatically.

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      one catch...

      identity columns ensures uniqueness but not "sequential-lity" (if there's even a word)...

      Comment

      • jeenajos
        New Member
        • Oct 2007
        • 71

        #4
        Thanks to all. I tried ur solution and its working....

        Comment

        Working...