Agent Jobs

Check If Column Exists In System Tables

If you have need to check if a column exists under System Tables (In this example we’ll look for the [containment] column which shows support for contained databases) here’s a quick bit of SQL logic that might help.

use master;
set nocount on

-- check for contained databases column under sys.databases
if col_length('sys.databases', 'containment') is null
    begin
        select 'Containment has not been found.'
    end
    else
        select 'Containment has indeed been found.'

Advertisements