How to add bulk values in column using DB Browser SQLite - sql

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;
}

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.

Related

Write value on subselect SQL query column in dbgrid

I need a join table from table 1 and table 2 and be able to apply updates on it so here's my SQL:
select
table1.ackode, tabble1.ket,
table1.debet, table1.kredit,
(select table2.ket from table2
where table2.kode = table1.ackode
and table2.ptlokasi = table1.ptlokasi) as x
from table1;
This resulted in a dbgrid like this :
now, whenever I click on ackode column, it'll open another form which I can select data from it. I wanted ACKODE and X column changed according to data values I've selected in that new form. However, it raised error as X column cannot be written.
is there any idea how to make it possible? I've set the X column's readonly property to false, however no such luck.
Thanks.

This Oracle SQL doesn't work in Oracle Apex

if :p6_internal_id is null then
INSERT INTO table
(
id,
account
)
values
(
tseq_id.nextval,
:p6_account,
);
else
update table set "all columns" where id = :p6_internal_id;
end if ;
This says
ORA-00927: missing equal sign
for the update set "all columns" line.
I don't know how to fix this. How do I set the value of all the columns where id is what I enter?
Based on your comments, you just need to change that line to:
update table set account = :p6_account where id = :p6_internal_id;
You don't need to set the id column to :p6_internal_id as you know it already has that value - since you're using it in the where clause.
There is no magic value of '"all columns"' that would allow every column to be updated at once, not least because you need to supply a value that corresponds to every column anyway, and in the right order.
If you have multiple columns to set then you have to list them all explicitly, with each column/value pair separated by commas; e.g. with a few made-up columns and bind variables:
update table set account = :p6_account,
name = :p6_name,
amount := p6_amount
where id = :p6_internal_id;
You can see the required syntax in the documentation.

add value to column after select

I have a button the executes a SELECT statement. When that button is clicked I need a query that counts + 1 in the column records.
So records can be 2. When I click the button + 1 should be added, so the new number in the column is 3. I am not quite sure how to do that. Is it modify column I have to use here?
ALTER stores MODIFY COLUMN records INT COUNT + 1;
First you have to stock the int you get in your first select query, I dont know which language you use but something like that
int result = "SELECT records FROM stores"
Then you increment your result
result++;
And you update the column with the new value
UPDATE stores SET records = " + result

How to add a record into table, that is related to another table?

Good day!
I have two tables.
TABLE 1:
GENERIC [GE_ID / number] [GE_DATEIN / date] [GE_PERSON / number] + ...
TABLE 2:
WORKFORCE [WF_ID / number] [WF_NAME / text] [WF_SHIFT / number] + ...
Column [GE_PERSON] from table #1 is related to the column [WF_ID] from table #2 as many-to-one relationship. I have a simple form to add a data to the table #1 with several drop down boxes. One of these drop down boxes contains a list of names taken from table #2 (column [WF_NAME]) by SQL statement.
So when I am ready to add a record to table #1, I know the person name chosen from drop down box, but column [GE_PERSON] is numeric and I have to add a number equal to the column [WF_ID] which is pointing on name in table #2 (column [WF_NAME]).
QUESTION: how should I build the SQL statement (INSERT INTO) to make this work?
Thank you!
MS Access' combobox control allows the bound column to be hidden from the user while showing identifiable data columns that correspond to hidden field. See this section of MS tutorial. Once you do so, you will have a relevant number for your querying needs.
Brief steps to hide and set primary key as bound column:
For the [WF Names] combobox, include [WF_ID] in the Row Source query under Data tab of Property Sheet as first column:
SELECT [WF_ID], [WF_NAME]
FROM [WORKFORCE]
Under Data tab make [WF_ID] the bound column by placing 1.
Under Format tab, set Column Count to 2 (or more for each field in query) but give Column Width to first column nothing, something like: 0; 2
Now the combobox's value is the corresponding [WF_ID] of the selected [WF_NAME] in drop down list, so any query pointing to the control will be a valid number:
INSERT INTO [GENERIC] ([GE_PERSON])
VALUES (Forms!formname!WFNamesComboBox)
SELECT * FROM [WORKFORCE]
WHERE [WF_ID] = Forms!formname!WFNamesComboBox

SQL insert row with one change

I have this table:
Table1:
id text
1 lala
And i want take first row and copy it, but the id 1 change to 2.
Can you help me with this problem?
A SQL table has no concept of "first" row. You can however select a row based on its characteristics. So, the following would work:
insert into Table1(id, text)
select 2, text
from Table1
where id = 1;
As another note, when creating the table, you can have the id column be auto-incremented. The syntax varies from database to database. If id were auto-incremented, then you could just do:
insert into Table1(text)
select text
from Table1
where id = 1;
And you would be confident that the new row would have a unique id.
Kate - Gordon's answer is technically correct. However, I would like to know more about why you want to do this.
If you're intent is to have the field increment with the insertion of each new row, manually setting the id column value isn't a great idea - it becomes very easy for there to be a conflict with two rows attempting to use the same id at the same time.
I would recommend using an IDENTITY field for this (MS SQL Server -- use an AUTO_INCREMENT field in MySQL). You could then do the insert as follows:
INSERT INTO Table1 (text)
SELECT text
FROM Table1
WHERE id = 1
SQL Server would automatically assign a new, unique value to the id field.