SQL programming

The following SQL code will recalculate comment counts for all nodes on your site.

update node_comment_statistics ncs set comment_count = (select count(*) from comment c where c.nid = ncs.nid) where 1=1

If you're reading this, you're probably wanting to change the collation of your mysql database to utf8_general_ci in order to support non-English characters.


update node_revisions as nr
JOIN node AS n ON n.nid = nr.nid
JOIN content_type_yoga_class AS yc ON yc.nid = nr.nid
JOIN content_type_location AS loc ON loc.nid = yc.field_class_location_nid

Not the most complicated bit of SQL I've ever written, but it took a bit of thinking about.

The following SQL script demonstrates how to perform multiple reverse DNS lookups from MS SQL Server.

The following SQL script will delete all tables from a Microsoft SQL Server Database.

After execution of this script, all of your data (and data tables) will be gone. Appropriate care should be exercised.

Subscribe to SQL programming