dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Resolved [RESOLVED] Reset an AUTOINCREMENT field in SQLite

    Hello everyone
    Can anyone please tell me how to reset an AUTOINCREMENT field after deleting all records?

    I learnt that I have to delete the sqlite_sequence table.
    I did so but still the autoincrement field not reset.

    Code:
     cnn.Execute "Delete from Tbl_Person"
    Code:
    cnn.Execute "Delete from sqlite_sequence where Name='Tbl_Person '"
    I tried also to update the sqlite_sequence table but without success.
    Code:
    cnn.Execute "UPDATE SQLITE_SEQUENCE SET SEQ=0 WHERE NAME='Tbl_Person'
    Thanks
    Last edited by samer22; Apr 16th, 2018 at 06:05 PM.

  2. #2
    PowerPoster
    Join Date
    Jun 2013
    Posts
    3,657

    Re: Reset an AUTOINCREMENT field in SQLite

    Quote Originally Posted by samer22 View Post
    Code:
      cnn.Execute "Delete from Tbl_Person"
    Instead of Deleting all Records from Tbl_Person (and trying to manipulate a "system-table"),
    I'd simply drop the whole table - and re-create it afterwards...
    Code:
    Dim SQLForCreate As String
        SQLForCreate = Cnn.DataBases(1).Tables("Tbl_Person").SQLForCreate 'get the DDL-string for the table
        Cnn.Execute "Drop Table Tbl_Person"
        Cnn.Execute SQLForCreate 're-create the table from the former definition
    HTH

    Olaf

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2013
    Posts
    595

    Re: Reset an AUTOINCREMENT field in SQLite

    Thank you sir very much

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width