Refresh denormalized fields

I just had to share this beautiful SQL Server query that I composed today. It refreshes denormalized fields!

UPDATE DestinationTable SET DestinationTable.Field=SourceTable.Field
FROM dbo.DestinationTableName AS DestinationTable
INNER JOIN dbo.SourceTableName AS SourceTable
ON SourceTable.PK=DestinationTable.FK

In other words, it copies the value from one column in one table to another column in another table, where the keys match (specified after ON). Beautiful! I use Microsoft SQL Server 2008, but I’m sure this works in 2005 too.

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll:

Bjud mig på en kopp kaffe (20:-) som tack för bra innehåll!

Comments

Important information: If you have not commented before, your comment will be reviewed before it is published. This means that you will not see it immediately, but I have received it. This is not because I want to filter comments, but because I want to prevent spam and advertising.

Leave a Reply

Your email address will not be published. Required fields are marked *