Updating a field in sql positive stories of online dating
This statement only updates one customer with an Id of 123.
The UPDATE statement doesn't limit you to one column. Suppose your customer wants to edit both his last and first names.
The data is a string with the value "Tom." If you attempt to store a string in a field designated as a numeric value, SQL throws you an error.
Finally, the WHERE clause limits the records edited.
The following UPDATE statement edits both columns at one time but still limits it to one customer: UPDATE Customer SET first_name = ‘Tom', last_name = ‘Smith' WHERE Customer Id = 123 The following two tables show you a before and after snapshot of your data when you run the SQL UPDATE statement: Before When you want to edit more than one column, you just append a comma to the end of the column section of the statement and add your column with a new value. If you recall from Lesson 2, NULL values are used when nothing is entered by the user or no value exists.
Your data administrator must allow NULL values in columns for you to use them.
If NULL values aren't allowed, SQL throws you an error when you edit values to NULL.
In this example, the table being edited is the Customer table.
If multiple records are returned in the WHERE clause, you update multiple records at once.
The following SQL statement updates all records where the customer has a NULL value for the first_name column: UPDATE Customer SET first_name = ‘No Value' WHERE first_name IS NULL The following tables give you a before and after snapshot: Before Sometimes, you need to edit records based on a SELECT statement.
In almost any application, the user must be able to edit data.
The user could have accidentally entered a typo or he didn't enter any information and you later ask him for it in the future.