Showing posts with label SQL. Show all posts
Showing posts with label SQL. Show all posts

Tuesday, 22 September 2015

Query all SQL DB sizes

Original source here

with fs
as
(
    select database_id, type, size * 8.0 / 1000 size
    from sys.master_files
)
select 
    name,
    (select sum(size) from fs where type = 0 and fs.database_id = db.database_id) DataFileSizeMB,
    (select sum(size) from fs where type = 1 and fs.database_id = db.database_id) LogFileSizeMB
from sys.databases db

However not all users have these permissions, script below to check a single table across multiple dbs.


Wednesday, 29 July 2015

Stored Procedure that disables failing Server Agent Jobs



I had a problem, I had a lot of development jobs that ran overnight, when they failed I got an email advising me of this. Then they failed again and again as they kept trying to run, this stored procedure monitors for failing jobs, using a user set limit and emails out a VERY bright red email to advise on what it's done.


Thursday, 8 January 2015

SQL Claims Triangles

Insurance claims triangles, getting the latest outstanding amount and the total amount paid

Includes

  • Temporary Tables
  • Updating tables using a join
  • While Statements
  • Alter statements

SQL Earned Premiums for Triangulations

Query to generate earned premiums, working based off the latest of either the entry date or the inception date

Contains

  • Temporary Tables
  • Calculated Columns
  • variables
  • While Loops