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. reset primary key (mysql)

reset primary key (mysql)

Scheduled Pinned Locked Moved Database
questiondatabasemysqltestingbeta-testing
6 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
    Jassim Rahma
    wrote on last edited by
    #1

    I have a primary key in StudentTable in mySQL database called (schoolDB)... I was using it for testing and now i want to rest the primary key to start from 1 how can I do that?

    E L H 3 Replies Last reply
    0
    • J Jassim Rahma

      I have a primary key in StudentTable in mySQL database called (schoolDB)... I was using it for testing and now i want to rest the primary key to start from 1 how can I do that?

      E Offline
      E Offline
      Estys
      wrote on last edited by
      #2

      Try this :

      ALTER TABLE yourTable AUTO_INCREMENT=1

      Be sure to delete all rows first. Cheers

      I don't like my signature at all

      1 Reply Last reply
      0
      • J Jassim Rahma

        I have a primary key in StudentTable in mySQL database called (schoolDB)... I was using it for testing and now i want to rest the primary key to start from 1 how can I do that?

        L Offline
        L Offline
        Luc Pattyn
        wrote on last edited by
        #3

        1. http://www.google.com/search?q=mysql+reset+primary+key[^] 2. IMO it should not matter; a primary key has one and only one function: it needs to be unique, it does not matter what the values actually are. :)

        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

        J 1 Reply Last reply
        0
        • L Luc Pattyn

          1. http://www.google.com/search?q=mysql+reset+primary+key[^] 2. IMO it should not matter; a primary key has one and only one function: it needs to be unique, it does not matter what the values actually are. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #4

          You're oversimplifying things a bit in my opinion. It does need to be unique, and it does not matter what the values actually are if you are using surrogate keys. But there is such a thing as natural keys, and there's nothing wrong in using them if it fits the model. Here[^] is yet another article on the subject by Joe Celko.

          "When did ignorance become a point of view" - Dilbert

          L 1 Reply Last reply
          0
          • J Jorgen Andersson

            You're oversimplifying things a bit in my opinion. It does need to be unique, and it does not matter what the values actually are if you are using surrogate keys. But there is such a thing as natural keys, and there's nothing wrong in using them if it fits the model. Here[^] is yet another article on the subject by Joe Celko.

            "When did ignorance become a point of view" - Dilbert

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            Jörgen Andersson wrote:

            You're oversimplifying things a bit in my opinion

            I'm sure I was. Thanks for the link, I'll read the article. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            1 Reply Last reply
            0
            • J Jassim Rahma

              I have a primary key in StudentTable in mySQL database called (schoolDB)... I was using it for testing and now i want to rest the primary key to start from 1 how can I do that?

              H Offline
              H Offline
              Hiren solanki
              wrote on last edited by
              #6

              Use

              DBCC CHECKIDENT('Customer', RESEED, 0)

              for Resetting Identity seed.

              Regards, Hiren. "We owe a lot to the Indians, who taught us how to count, without which no worthwhile scientific discovery could have been made." - Einstein Microsoft Dynamics CRM

              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