Friday, June 8, 2012

runas syntax

C:\Users\epsi>runas /user:domain\user "D:\Program Files (x86)\Microsoft SQL
Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe"

Displaying Table Sizes using T-SQL

For each table get table size

http://blog.securahosting.com/technical/databases/displaying-table-sizes-using-t-sql/

SELECT LEFT(OBJECT_NAME(id), 30) AS [Table],
CAST( CAST(reserved * 8192 AS DECIMAL(10,1)) / 1000000.0 AS DECIMAL(10,1)) AS 'Allocated (MB)',
CAST(CAST(dpages * 8192 AS DECIMAL(10,1)) / 1000000.0 AS DECIMAL(10,1)) AS 'Used (MB)',
CAST(CAST((reserved - dpages) * 8192 AS DECIMAL(10,1)) / 1000000.0 AS DECIMAL(10,1)) AS 'Unused (MB)',
rowcnt AS 'Row Count (approx.)'
FROM sysindexes WHERE indid IN (0, 1) AND OBJECT_NAME(id) NOT LIKE 'sys%' AND OBJECT_NAME(id) NOT LIKE 'dt%'
ORDER BY reserved DESC, LEFT(OBJECT_NAME(id), 30)

Wednesday, June 6, 2012

SQL Database Mail "NOTE: Failed to notify 'operator' via email."

Credit: http://leopard-solutions.com/blog/post/2011/06/15/SQL-Database-Mail-NOTE-Failed-to-notify-operator-via-email.aspx

If you have set up your SQL Database Mail Operators and SMTP details correctly, but keep getting a message like this: "NOTE: Failed to notify 'operator' via email.", you may not have enabled the Alert System In the SQL Server Agent.

Here's how to enable the Mail System:

Right click "SQL Server Agent" in the Object Explorer and click "Properties"

Go to Alert System, and check the "Enable mail profile" box and select the correct Mail system and Mail profile.