SQL Server Autofix Logins

I need these commands all the time when restoring databases. This will lists the orphaned users:

 EXEC sp_change_users_login 'Report'

If you already have a login id and password for this user, fix it by doing:

 EXEC sp_change_users_login 'Auto_Fix', 'user'

If you want to create a new login id and password for this user, fix it by doing:

 EXEC sp_change_users_login 'Auto_Fix', 'user', 'login', 'password'

Hat tip here.

Find a String in a Stored Procedure

Use this handy query to find all procedures containing the search string @Search

DECLARE @Search varchar(255)
SET @Search='Document'

SELECT DISTINCT
 o.name AS Object_Name,o.type_desc
 FROM sys.sql_modules m 
 INNER JOIN sys.objects o ON m.object_id=o.object_id
 WHERE m.definition Like '%'+@Search+'%'
 ORDER BY 2,1

Thanks to StackOverflow for this. Or alternatively make use of the information_schema:

SELECT ROUTINE_NAME, ROUTINE_TYPE, ROUTINE_DEFINITION 
 FROM INFORMATION_SCHEMA.ROUTINES 
 WHERE ROUTINE_DEFINITION LIKE '%Document%'

Hat tip here.

Getting Started With Visual Studio 2012 Express

Microsoft’s Express series of development tools are all free. A couple of links to help you get started with web development: