Content
UPDATE modifies existing records in a table. Always use WHERE to avoid updating all rows accidentally.
Basic UPDATE Syntax
UPDATE table_name SET column = value WHERE condition;
Update Single Column
UPDATE customers SET status = 'active' WHERE id = 123;
Update Multiple Columns
UPDATE products
SET price = 29.99, stock = 100
WHERE product_id = 456;
Update with Calculation
UPDATE products SET price = price * 1.1 WHERE category = 'Electronics';
Update with Subquery
UPDATE orders
SET status = 'shipped'
WHERE customer_id IN (SELECT id FROM customers WHERE premium = true);
Safe UPDATE Practice
-- Always test with SELECT first
SELECT * FROM products WHERE category = 'Books';
-- Then run UPDATE
UPDATE products SET discount = 0.2 WHERE category = 'Books';
Generate UPDATE Queries
Describe what you want to change and AI2sql writes safe UPDATE statements.


