Skip to content

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.

Categories: Microsoft .NET.

Tags:

Comment Feed

No Responses (yet)



Some HTML is OK

or, reply to this post via trackback.

*