Category: Applied SQL

Applied SQL: Orphan a user, fix orphaned users (sp_FixOrphanedUsers)

Ever heard of orphaned users? It’s a database user account, disconnected from its associated login. You typically get this when you take a database backup, and restore it to a different server. Microsoft provides us with the ever helpful sp_change_users_login to find and repair orphaned users, but even so, it’s kind of a PITA* manual operation. […]

Applied SQL: LIKE ‘whatever’

Today let’s play around with the LIKE operator. Like, totally. Like, Introduction Like “determines whether a specific character string matches a specified pattern. A pattern can include regular characters and wildcard characters.” That makes it pretty darn useful, say, when we’re searching for all product reviews with the word “worst” in it: SELECT ID, Comments […]

Applied SQL: Find and replace using regular expressions in SSMS

Regular expressions are searches on steroids, the wildcats of the wildcard world*.  Even if you  never ever write CLR, regex (as it’s affectionately known) can be useful to you today, right now. Open a new query window in SQL Server Management Studio. Type “xyz”, hit enter twice, and type “xyz” again. Now hit CTRL-H to […]