Questions tagged [sql-update]

An SQL UPDATE statement is used to change existing rows in a table.

An SQL UPDATE statement is used to change existing rows in a table.

The basic syntax is:

UPDATE table 
SET 
    Column1 = 'x',
    Column2 = 'y'
WHERE id=1

Tagging Recommendation

This tag should be used for general SQL programming language questions, in addition to tags for specific products. For example, questions about Microsoft SQL Server should use the tag, while questions regarding MySQL should use the tag. Tagging by product (including version, e.g , ) is the easiest way to know what functionality is available for the task at hand.

References

12009 questions
31
votes
1 answer

Using cross apply in update statement

Is it possible to use the cross apply clause in the from part of an update statement, in SQL Server 2005?
Guillermo Gutiérrez
  • 17,273
  • 17
  • 89
  • 116
31
votes
5 answers

UPDATE with CASE and IN - Oracle

I wrote a query that works like a charm in SQL Server. Unfortunately it needs to be run on an Oracle db. I have been searching the web inside out for a solution on how to convert it, without any success :/ The query looks like this i SQL: UPDATE…
user641605
  • 421
  • 1
  • 5
  • 10
31
votes
7 answers

MySQL Update Column +1?

I was wondering what would be the easiest way to update a column by +1? I will be updating a post count of a category based on when users submits a new post. Thanks.
Cory
  • 732
  • 3
  • 7
  • 22
31
votes
5 answers

Android SQLite Database, WHY drop table and recreate on upgrade

In the tutorials I am following and a lot of more places I see this, onUpgrade -> drop table if exists, then recreate table. What is the purpose of this? private static class DbHelper extends SQLiteOpenHelper{ public DbHelper(Context context)…
Esqarrouth
  • 38,543
  • 21
  • 161
  • 168
30
votes
12 answers

Table is 'read only'

When I want to execute an update query on my table I got an error saying: 1036 - Table data is read only. How can I fix that? Table attributes in /var/db/mysql are set to 777. 'Repair Table' function doesnt seems to help. Is there anything I can…
Cyclone
  • 14,839
  • 23
  • 82
  • 114
30
votes
3 answers

Can you replace or update a SQL constraint?

I have written the following constraint for a column I've called 'grade': CONSTRAINT gradeRule CHECK grade IN (‘easy’, ‘moderate’, ‘difficult’), Is it possible to later update the gradeRule to have different values? For example, 'moderate' and…
StormFoo
  • 1,129
  • 2
  • 10
  • 25
30
votes
2 answers

Entity Framework Attach/Update confusion (EF Core)

As I understand, when "Update" is called, every property within a specific entity is modified. The "Attach" method, on the other hand, starts the entity off in the "Unmodified" state. Then, when an operation takes place on a particular property,…
J Marlow
  • 744
  • 1
  • 5
  • 11
29
votes
1 answer

How to create and insert a JSON object using MySQL queries?

I'm trying to create a JSON object and then read the values from it into MySQL table. But I'm facing errors and I'm new to both JSON and MySQL. SET @j = '{"key1": "value1", "key2": "value2"}'; CREATE TABLE Person (name int,id int); INSERT INTO…
rj_23495
  • 293
  • 1
  • 3
  • 6
29
votes
2 answers

How to do a cascading update?

I have a group of tables with columns that have foreign key constraints on a user name column in another table. I've been instructed not to add ON UPDATE CASCADE to the table definition because we don't want to silently lose information from things…
Joe M
  • 3,060
  • 3
  • 40
  • 63
29
votes
3 answers

PHP UPDATE prepared statement

I'm trying to learn the proper way to use prepared statements to avoid SQL injections etc. When I execute the script I get a message from my script saying 0 Rows Inserted, I expect this to say 1 Rows Inserted and of course update the table. I'm not…
user0129e021939232
  • 6,205
  • 24
  • 87
  • 140
29
votes
2 answers

Postgres update from left join

I'm new in PostgreSQL and trying to convert a query from SQL Server. I have a table Users with, among others, the columns bUsrActive, bUsrAdmin and sUsrClientCode. I want to update Users and set bUsrActive = false if there does not exist a another…
alfoks
  • 4,324
  • 4
  • 29
  • 44
28
votes
4 answers

How to use update trigger to update another table?

I am new to triggers and want to create a trigger on an update of a column and update another table with that value. I have table1 with a year column and if the application updates that year column I need to update table 2 with the year the same…
Spafa9
  • 742
  • 3
  • 14
  • 30
28
votes
2 answers

copy one column from one table to another

I am confused about how to copy a column from one table to another table using where. I wrote SQL query but it says transaction lock time exceeded or query returns more than one row. using mysql Basically, I have: Table 1: Results BuildID …
JPro
  • 6,292
  • 13
  • 57
  • 83
28
votes
2 answers

update multiple rows using limit in mysql?

UPDATE messages set test_read =1 WHERE userid='xyz' ORDER BY date_added DESC LIMIT 5, 5 ; I am trying to use this query to update a set of 5 rows using limit but mysql is showing an error..The one below is working …
halocursed
  • 2,451
  • 5
  • 27
  • 34
27
votes
2 answers

How to update a varbinary field with a specific value?

Basically I am trying to give a user a certain password so I can test some functionality on a system, as I only have our admin account and I can't play with that I am just picking a random account so I can do my testing. So here is my attempt at an…
shicky
  • 2,076
  • 5
  • 30
  • 44