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
42
votes
7 answers

How to handle-escape both single and double quotes in an SQL-Update statement

I have this sample T-SQL query and trying this on SQL-Server-2008. DECLARE nvarchar(1000) @wstring = "I asked my son's teacher, "How is my son doing now?"" UPDATE tablename SET columnname = ' " & @wstring & " ' where ... blah ... blah I know…
MukeshAnAlsoRan
  • 671
  • 2
  • 6
  • 13
42
votes
3 answers

Python mySQL Update, Working but not updating table

I have a python script which needs to update a mysql database, I have so far: dbb = MySQLdb.connect(host="localhost", user="user", passwd="pass", db="database") try: curb = dbb.cursor() curb.execute ("UPDATE…
user2144306
  • 423
  • 1
  • 4
  • 4
42
votes
5 answers

Difference between Alter and Update SQL

I am busy studying MySQL and I understand that update is used to update a record or row in a table. So what does alter do that is so different? Seems like they are the same. Thanks, any help will be appreciated.
Artic-M00n
  • 533
  • 2
  • 8
  • 15
41
votes
3 answers

Advanced MySql Query: Update table with info from another table

I would like to update a table in mySql with data from another table. I have two tables "people" and "business". The people table is linked to the business table by a column called "business_id". The necessary table structure, primary key is…
superUntitled
  • 22,351
  • 30
  • 83
  • 110
40
votes
5 answers

Update rows in one table with data from another table based on one column in each being equal

Update many rows into one table from another table based on one column in each being equal (user_id). both tables have a user_id column. Need to insert data from t2 into t1 when the user_id column are equal.
JcR49
  • 529
  • 1
  • 5
  • 7
40
votes
5 answers

UPDATE statement with multiple joins in PostgreSQL

I'm trying to update a table called incode_warrants and set the warn_docket_no to the viol_docket_no from the incode_violations table. I have the following SQL query in Postgres 9.3, but when it fires I get the following error: Error : ERROR: …
nulltek
  • 3,247
  • 9
  • 44
  • 94
40
votes
3 answers

How to update with Sequelize with 'NOW()' on a timestamp?

I'm trying to do something like the following: model.updateAttributes({syncedAt: 'NOW()'}); Obviously, that doesn't work because it just gets passed as a string. I want to avoid passing a node constructed timestamp, because later I compare it to…
Ben
  • 458
  • 1
  • 5
  • 9
39
votes
2 answers

Equivalent of ON CONFLICT DO NOTHING for UPDATE postgres

I want to update rows in my postgres database if the updated version wouldn't violate the primary key constraint. If it would, I want to leave the row as it is. Assuming the table has primary keys on col1, col2, col3, if I run a query like…
BHC
  • 889
  • 1
  • 7
  • 18
38
votes
5 answers

Update columns with Null values

I tried updating a table as follows: update userloginstats set logouttime = sysdate where logouttime = null; It didn't update the columns with null values. What went wrong?
nath
  • 2,848
  • 12
  • 45
  • 75
38
votes
2 answers

Conditional UPDATE in MySQL

I am trying to UPDATE values from a table, but I need to add some conditions. I found the function CASE, but I am not if it is the best method. Here is an example. My table is 'relation': userid1 | userid2 | name1 | name2 I got for example: SELECT…
Pierre Lebon
  • 445
  • 1
  • 5
  • 12
38
votes
4 answers

mysql after insert trigger which updates another table's column

i'm trying to write a trigger, I have following tables: BookingRequest: +-----------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | …
DeadKennedy
  • 749
  • 3
  • 14
  • 22
37
votes
5 answers

Bulk Record Update with SQL

I have two tables in a SQL Server 2008 environment with the following structure Table1 - ID - DescriptionID - Description Table2 - ID - Description Table1.DescriptionID maps to Table2.ID. However, I do not need it any more. I would like to do a…
user208662
  • 10,869
  • 26
  • 73
  • 86
37
votes
5 answers

Delete specific values from column with where condition?

I want to delete specific values/data from one column with the WHERE condition. Putting in another way, I don't want to delete the complete row. Is it possible?
tina
  • 371
  • 1
  • 3
  • 3
37
votes
6 answers

How to update only one row in a table?

How to I can update only one record in a table? Table: name name1 name2 ---------------------------- xx xy xz xx xx xx xx xx xx xx xx xx xy xx …
Klapsius
  • 3,273
  • 6
  • 33
  • 56
37
votes
6 answers

What are differences between INSERT and UPDATE in MySQL?

It seems INSERT and UPDATE do the same things to me. Is there any occasions where I should use INSERT instead of UPDATE and vice versa?
shin
  • 31,901
  • 69
  • 184
  • 271