简体   繁体   中英

Update each column's value pertaining to a specific row number? sqlite sqlite3

I and terrible with databases and sql, but know the basics and this is a bit beyond basics I believe. I need a way to update a an entire rows values, where the row is selected by row number, because I have no guarantee of a value pertaining to any of the columns in that row.

Example DB Table:

Col1    Col2    Col3
a       b       c
d       e       f
g       h       i

So I need a way to for say

Update exampleTableName 
Set Col1 = 'j', Col2 = 'k', Col3 = 'l'
Where rowNumber = 2

I am writing this in c++ and using sqlite3, but just the Query should do for me.

Thanks

Edit:

I know this sounds ridiculous and many will ask why the table is set up this way but I am not in control of that. All I can say is that I am able to figure out a row number and need to update each columns value according to what is stored in another variable. Normally these variables will hold the value I want to look up, but it isn't ever guaranteed. So I can only recall the row they want and store it at the time of the look up and then update (the last selected row) by keeping track up its index and updating its values according to w/e is in those variables, which could be the same or could have changed.

By default, every row in SQLite has a special column, usually called the "rowid", that uniquely identifies that row within the table. You can use that to select your row.

However if the phrase "WITHOUT ROWID" is added to the end of a CREATE TABLE statement, then the special "rowid" column is omitted. There are sometimes space and performance advantages to omitting the rowid.

Update exampleTableName Set Col1 = 'j', Col2 = 'k', Col3 = 'l'   Where rowid= 2

您的表需要某种形式的主键...至少应添加一个名为Key INT IDENTITY(1,1)的列,这将为每一行提供一个数字。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM