sql-update

Atomic increment of counter column using simple update

帅比萌擦擦* 提交于 2020-06-13 19:33:50
问题 I am trying to understand how to safely increment a counter column, that may be incremented simultaneously by many users (It's a Web API for a mobile app). I've read the popular questions in SO for strategies dealing with the issue but I can't seem to figure what's wrong with using a simple: UPDATE Table SET Counter = Counter + 1 I've built the following code sample to try and get inconsistent values and prove myself that using only this simple update statement is not good practice: class

What is the fastest way to update SQL rows with values, based upon a value in the row?

落爺英雄遲暮 提交于 2020-05-31 06:30:31
问题 I have the following table in SQL Server called tblProducts : +-----------+--------------+-------------+ | pkProduct | fkProductID | intIssue | +-----------+--------------+-------------+ | 1 | 10 | 1 | | 2 | 10 | 2 | | 3 | 10 | 4 | | 4 | 11 | 1 | | 5 | 11 | 2 | | 6 | 11 | 3 | | 7 | 11 | 5 | | 8 | 12 | 1 | | 9 | 13 | 1 | | 10 | 13 | 4 | | 11 | 14 | 1 | | 12 | 14 | 3 | | 13 | 14 | 6 | | 14 | 15 | 1 | | 15 | 16 | 1 | +-----------+--------------+-------------+ Over time, with rows having being

syntax to UPDATE a BLOB field in an existing SQLite record?

我的未来我决定 提交于 2020-05-17 07:41:46
问题 What is the syntax to UPDATE a BLOB field in an existing SQLite record, using Python? I create a 13x13 array of floats and want to Update a specific record (i.e. using a WHERE clause) in my table with that array. What is the proper UPDATE syntax? The array has the following form: [ 4.65640926e+00 5.59250259e+00 5.28963852e+00 1.60680866e+00 -3.39492680e-01 -4.76834650e-01 -4.76834650e-01 -2.29132240e-01 1.49733067e+00 1.51563072e+00 1.49733067e+00 9.53471420e-01 -1.40306473e+00] [ 5.28963852e

Data Integrity issue query fix logic oracle sql

痴心易碎 提交于 2020-05-17 07:09:27
问题 I have a table and in this table i have data is not properly loaded data integrity issue ,since this is a dimension table we need to maintain the effective_dt_from and effective_dt_to and version correctly ,below is the table and sample data create table TEST ( LOC_SID NUMBER(38,0), CITY VARCHAR2(180 BYTE), POSTAL_CD VARCHAR2(15 BYTE), EFFECTIVE_DT_FROM DATE, EFFECTIVE_DT_TO DATE, VERSION NUMBER(38,0) ); Insert into TEST values (25101,'Assam',1153,to_date('01.01.00 00:00:00','DD.MM.YY HH24:MI

MySQL query add duration to previous record

末鹿安然 提交于 2020-05-17 07:07:33
问题 I like to add event duration to a previous record every time a new record gets added. This is what I have ID EventType EventTime EventDuration ------------------------------------- 1 TypeA 10:20 NULL 2 TypeB 09:30 NULL 3 TypeC 08:00 NULL This is what I want to achieve: ID EventType EventTime EventDuration ------------------------------------- 1 TypeA 10:20 00:50 2 TypeB 09:30 01:30 3 TypeC 08:00 ... 4 ... ... When a new records gets added (with ID, EventType and EventTime), the duration of

MySQL query add duration to previous record

爱⌒轻易说出口 提交于 2020-05-17 07:07:01
问题 I like to add event duration to a previous record every time a new record gets added. This is what I have ID EventType EventTime EventDuration ------------------------------------- 1 TypeA 10:20 NULL 2 TypeB 09:30 NULL 3 TypeC 08:00 NULL This is what I want to achieve: ID EventType EventTime EventDuration ------------------------------------- 1 TypeA 10:20 00:50 2 TypeB 09:30 01:30 3 TypeC 08:00 ... 4 ... ... When a new records gets added (with ID, EventType and EventTime), the duration of

Postgres error updating column data

点点圈 提交于 2020-05-17 05:43:06
问题 Trying to run a update script on a table, but getting an error: ERROR: column "ok" does not exist LINE 2: SET first_name="ok", last_name="pk", email="ooo", phone="... CREATE TABLE employee ( employee_id SERIAL PRIMARY KEY, first_name varchar(255) NOT NULL, last_name varchar(255) NOT NULL, email varchar(255) NOT NULL, phone varchar(255) ); INSERT INTO employee( first_name, last_name, email, phone) VALUES ('Kyle', 'Belanger', 'kbelanger@ok.com', '(240) 298-4664'); UPDATE "employee" SET first

MySQL - SELECT then UPDATE

这一生的挚爱 提交于 2020-05-10 04:06:45
问题 I have a script written in PHP which has this line which is working correctly for selecting the data i need; $result = mysql_query("SELECT product_name, sku, qty FROM supplier_dropship_items WHERE supplier_id = '3' AND status = '2'", $db_beb); What I'm struggling with is a way to update the records I have selected, once selected I need to change the status = '1' so that the next time my script runs it won't pull the same data in the select and will only pull new items in the table which have

MySQL - SELECT then UPDATE

ε祈祈猫儿з 提交于 2020-05-10 04:04:49
问题 I have a script written in PHP which has this line which is working correctly for selecting the data i need; $result = mysql_query("SELECT product_name, sku, qty FROM supplier_dropship_items WHERE supplier_id = '3' AND status = '2'", $db_beb); What I'm struggling with is a way to update the records I have selected, once selected I need to change the status = '1' so that the next time my script runs it won't pull the same data in the select and will only pull new items in the table which have

How to update one table from another table based on some priority that depends on where clause?

ⅰ亾dé卋堺 提交于 2020-04-17 22:08:00
问题 I have table A with product_id,cost,year,quarter,... etc columns. I have another table B with product_id,base_cost,current_year,p_year,p_quarter,p_order columns. I want to write an update query to update A from B. My conditions are - WHERE A.product_id=B.product_id and A.year=B.current_year and (A.year=B.p_year and A.quarter>B.p_quarter) or A.year>B.p_year and A.cost=0; But the problem is, with these conditions if i have more than one rows in B then i only want to update from the row of B