Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Display Row Number

Display Row Number

Scheduled Pinned Locked Moved Database
questiondatabasesql-servercomsysadmin
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jason Weibel
    wrote on last edited by
    #1

    I am trying to reset the PK on a SQL Server table. The key is auto populated and automatically increments by 1. I have cleared all the data and want to repopulate. Is there a way to have the first Id be equal to 1? Currently numbering starts where the last data ended. Second question is there a way to print the row number in a select statement? Jason W.

    M R C R 4 Replies Last reply
    0
    • J Jason Weibel

      I am trying to reset the PK on a SQL Server table. The key is auto populated and automatically increments by 1. I have cleared all the data and want to repopulate. Is there a way to have the first Id be equal to 1? Currently numbering starts where the last data ended. Second question is there a way to print the row number in a select statement? Jason W.

      M Offline
      M Offline
      Michael P Butler
      wrote on last edited by
      #2

      If I remember correctly, to reset the row number field you need to TRUNCATE TABLE. Michael "I've died for a living in the movies and tv. But the hardest thing I'll ever do is watch my leading ladies, Kiss some other guy while I'm bandaging my knee." -- The Unknown Stuntman

      J 1 Reply Last reply
      0
      • M Michael P Butler

        If I remember correctly, to reset the row number field you need to TRUNCATE TABLE. Michael "I've died for a living in the movies and tv. But the hardest thing I'll ever do is watch my leading ladies, Kiss some other guy while I'm bandaging my knee." -- The Unknown Stuntman

        J Offline
        J Offline
        Jason Weibel
        wrote on last edited by
        #3

        Exactly what I was looking for thanks. :) Jason W.

        1 Reply Last reply
        0
        • J Jason Weibel

          I am trying to reset the PK on a SQL Server table. The key is auto populated and automatically increments by 1. I have cleared all the data and want to repopulate. Is there a way to have the first Id be equal to 1? Currently numbering starts where the last data ended. Second question is there a way to print the row number in a select statement? Jason W.

          R Offline
          R Offline
          Robby
          wrote on last edited by
          #4

          you can also do this by changing your identity to "NO" in the design view, saving the table and then re-instating the identity to YES

          1 Reply Last reply
          0
          • J Jason Weibel

            I am trying to reset the PK on a SQL Server table. The key is auto populated and automatically increments by 1. I have cleared all the data and want to repopulate. Is there a way to have the first Id be equal to 1? Currently numbering starts where the last data ended. Second question is there a way to print the row number in a select statement? Jason W.

            C Offline
            C Offline
            Carlos Antollini
            wrote on last edited by
            #5

            The only mode that I know, is removing the PK state, repopulating the fileld and setting like PK again... Carlos Antollini. Sonork ID 100.10529 cantollini

            1 Reply Last reply
            0
            • J Jason Weibel

              I am trying to reset the PK on a SQL Server table. The key is auto populated and automatically increments by 1. I have cleared all the data and want to repopulate. Is there a way to have the first Id be equal to 1? Currently numbering starts where the last data ended. Second question is there a way to print the row number in a select statement? Jason W.

              R Offline
              R Offline
              Rein Hillmann
              wrote on last edited by
              #6

              To reseed your identity column you can use the following dbcc command. Not too sure if it's supported though: dbcc checkident ( <tablename>, RESEED, <newvalue> ) example: dbcc checkident(authors, RESEED, 100000)

              R 1 Reply Last reply
              0
              • R Rein Hillmann

                To reseed your identity column you can use the following dbcc command. Not too sure if it's supported though: dbcc checkident ( <tablename>, RESEED, <newvalue> ) example: dbcc checkident(authors, RESEED, 100000)

                R Offline
                R Offline
                Rein Hillmann
                wrote on last edited by
                #7

                Oh, and for ther row number you might want to check out this link: http://www.sqlteam.com/item.asp?ItemID=1491

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups