Wednesday, January 23, 2013

MSSQL Connect to a database from a TSQL script

Step 1:

Switch to SQLCMD mode from the query menu in Management Studio:

Step 2:
Add the connection info using:
:Connect server_name[\instance_name] [-l timeout] [-U user_name [-P password]]
Till Next Time

Monday, January 21, 2013

MSSQL Check if Function or Procedure has changed

I use this query to check if a procedure or function has changed in the past 5 days:
[code]
SELECT * from ods.information_schema.routines i where routine_type in ('PROCEDURE' ,'FUNCTION') AND LAST_ALTERED > getdate() - 5
[/code]

Till Next Time