1

I have a table that contain two columns. One column "rewords" contain 12186 words. and the other column named "ID" is the column that I newly created so it is empty. I want to add numbers against the rewords column. numbers from 1, 2, 3, to 12186. i tried to use primary key not null operation but it disturbs the order and its sequence becomes unpredictable like 1,2,6,10,7,8,19.... If I manually type 1,2,3 in the fields, then it will be too time-consuming and effortful. Following is the screenshot of what I desire. I want that I could have typing from 1 to 12186 in the fields of ID column.

I also tried the following function in the query tab, but it doesn't work and gives error that "near "for": syntax error: for"

for(int i = 1; i<=12186; i++){
    UPDATE tbl SET ID = i WHERE index = i;
}

enter image description here

Surraya Marvi
  • 131
  • 1
  • 11

1 Answers1

1

you don't need the loop you can do this with a single query

UPDATE tbl 
SET ID =  index 
WHERE index  <= 12186;

otherwise if you have not a column index .. you need an autoincrement value in you id column .. you should

You can do it with SQLite Expert Personal 4:

1) Select the table and then go to "Design" tab > "Columns" tab.

2) Click select the ID column name, and type INTEGER and Not Null > Ok.

3) Go to "Primary Key" tab in "Desgin tab". 
      Click "Add" and select the column ID. Check the "Autoincrement" box.

4) Click "Apply" on the right bottom part of the window.
ScaisEdge
  • 131,976
  • 10
  • 91
  • 107