auto_increment

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rameshkumarc
    New Member
    • Jan 2007
    • 14

    #1

    auto_increment

    i m having one table with column (sno,name,addr, age)like that...i set the sno as auto_increment as well as primary key.........i m deleting all the records in the table...if i m inserting the new records the sno was not starting form 1..it's starting from old maximum value that i deleted.....i need to start the auto_increment from 1...can any one plz give the solution for my pbm?..
  • bartonc
    Recognized Expert Expert
    • Sep 2006
    • 6478

    #2
    Originally posted by rameshkumarc
    i m having one table with column (sno,name,addr, age)like that...i set the sno as auto_increment as well as primary key.........i m deleting all the records in the table...if i m inserting the new records the sno was not starting form 1..it's starting from old maximum value that i deleted.....i need to start the auto_increment from 1...can any one plz give the solution for my pbm?..
    You could DROP the table and recreate it. Should work.

    Comment

    • rameshkumarc
      New Member
      • Jan 2007
      • 14

      #3
      if there is any other solution without dropping the table

      Comment

      • write2ashokkumar
        New Member
        • Feb 2007
        • 39

        #4
        hi...

        If u want to delete all the records from the table means, use the command "truncate".

        syntax:

        truncate table <table_name>;

        after truncating the table, if u insert the record, the auto increment value
        starts from 1.


        Regards,
        S.Ashokkumar.

        Comment

        • write2ashokkumar
          New Member
          • Feb 2007
          • 39

          #5
          hi...

          Another one method...

          after deleting all the records, use the alter command to reset the auto increment value.

          Ex: alter table tbl_xxx auto_increment = 1

          Refer this link:
          http://www.scriptygodd ess.com/archives/2004/06/24/reset-autoincrement-value-in-mysql-tabl/

          Regards,
          S.Ashokkumar.

          Comment

          • rameshkumarc
            New Member
            • Jan 2007
            • 14

            #6
            ya it's working now....thanks for ur solution mr.ashok kumar

            Comment

            Working...