sql - Checking if table exists and has default values -
can make below 2 checking in 1 select ? checking first if table exists checking if has default value.
can check in 1 select if table exists , has default value ?
if exists (select 1 syscolumns c c.id = object_id('ex_employee') , c.name = 'b_time') begin if not exists(select * sys.all_columns c join sys.tables t on t.object_id = c.object_id join sys.schemas s on s.schema_id = t.schema_id join sys.default_constraints d on c.default_object_id = d.object_id t.name = 'ex_employee' , c.name = 'b_time') begin execute ('alter table ex_employee add default 1 b_time') end end go
so if need check both conditions in 1 if clause can below.
if exists (select 1 syscolumns c c.id = object_id('ex_employee') , c.name = 'b_time') , not exists(select * sys.all_columns c join sys.tables t on t.object_id = c.object_id join sys.schemas s on s.schema_id = t.schema_id join sys.default_constraints d on c.default_object_id = d.object_id t.name = 'ex_employee' , c.name = 'b_time') begin .... end
Comments
Post a Comment