![]() Notice that on this occasion the response is UPDATE 4. We want to make Harry Potter and Jane Smith active users once again. We previously set all users to be disabled. Using a WHERE clause lets us update only the specific rows that meet the condition(s) set in that clause. In general, you'll update specific rows based on some criteria by including a WHERE clause. Updating all the rows in a table like this is fairly unusual. This includes the row where enabled already had a value of false. The UPDATE 5 response tells us how many rows had the value for the enabled column set to false by our UPDATE statement. One thing we might want to do in our users table is disable all of our users at once, for example in response to a security issue. First we'll look at updating all of the rows in a table, and then how to target specific rows to be updated. Let's try out UPDATE with a few simple examples. You can always test your WHERE clause in a SELECT statement to check which rows are being targeted, before then using it in an UPDATE statement. Even when using a WHERE clause care must be taken to ensure that it is restrictive or specific enough to target only the rows that you want to modify. If omitted, PostgreSQL will update every row in the target table, so before executing such a query be sure that this is actually what you want to do. ![]() The WHERE clause in the above syntax example is optional. We can specify any table in our database to update and specify any number of columns within that table. This statement can be read as, "Set column(s) to these values in a table when an expression evaluates to true". ![]() ) indicates that you can specify multiple column_name = value entries.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |