W3. SQL Update Flashcards
Q: What is the purpose of the SQL UPDATE statement?
A: To modify existing records in a table.
Q: What is the syntax for the UPDATE statement?
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
Q: Why is the WHERE clause important in an UPDATE statement?
A: It specifies which records to update; omitting it updates all records in the table.
Q: Write an example query to update the contact name and city for the customer with CustomerID = 1.
UPDATE Customers SET ContactName = 'Alfred Schmidt', City = 'Frankfurt' WHERE CustomerID = 1;
Q: How does the WHERE clause affect the number of records updated?
A: It limits the update to records that meet the specified condition(s).
Q: Write a query to set the ContactName to “Juan” for all records where the country is “Mexico.”
UPDATE Customers SET ContactName = 'Juan' WHERE Country = 'Mexico';
Q: What happens if you omit the WHERE clause in an UPDATE statement?
A: All records in the table will be updated.
Q: Provide an example of an UPDATE statement without a WHERE clause.
UPDATE Customers SET ContactName = 'Juan'; (This will update the ContactName for all records in the table.)