So, yet again, we’re talking about data sources and what all you can do with them. Here, we show what all there is. And as before, we’re still going to use a database for our examples.
So, now on with the show. This time we look at: Update it with data from another data source
The syntax for updating a database table is quite close to the SELECT statement seen in our last post here.
UPDATE [SampleTable] SET FirstName = ‘Tom’ WHERE FirstName = ‘Thomas’;
In this case, we’re using our favorite database table of all time – SampleTable . The word UPDATE tells the database that we want to replace one value with another value. The word FirstName represents a field that, in this case, is a column that shows all of the first names of the people in the SampleTable. The word WHERE and the part after it tells the database to look for any row that has a value of “Thomas” in the FirstName column and change it to “Tom.”
Now there is another syntax that is even closer to the SELECT statement, but it’s not used quite as often. We’ll even rearrange the query above into the correct syntax to make it even easier to understand.
SET FirstName = ‘Tom’
FROM [SampleTable] S
WHERE FirstName = ‘Thomas’;
Now, I broke this out into several lines just to make it easier to read and discuss. You can do the same thing with the other examples – in fact, it’s considered a best practice to do so.
The biggest difference you’ll see is that there is a letter S after the name of the table – in our case, SampleTable . The S is used as an alias for the SimpleTable so that we can more quickly reference the table. Now, it can be more than one letter (and probably should in most cases), but we’ll keep it simple for now. Please note that the alias S is used after the word UPDATE.
And so with that, we finish our post on Updating. Please remember if you have any questions or comments, please leave a comment on this page. So, please join us next time…