I've researched how to test for the existence of a table or constraint when deleting database items in SQL Server 2016 and learned that the 'if exist' syntax can be used for this. But I haven't worked out how to delete a table's constraints, followed by deleting the table itself, in cases where the table itself may or may not exist without the script erroring.
-- Drop TABLE1
alter table TABLE1 drop constraint if exists F_TABLE1_COLUMN1
go
alter table TABLE1 drop constraint if exists F_TABLE1_COLUMN2
go
alter table TABLE1 drop constraint if exists P_TABLE1_COLUMN2
go
drop table if exists TABLE1
go
In this example the script will error attempting to delete the constraint if the table does not exist.
How should I script this?