raise error if table does not exists in database

sql-server-2008

Solution

One way

IF NOT  EXISTS (SELECT * FROM sys.objects 
WHERE object_id = OBJECT_ID(N'[dbo].[table1 ]') AND type in (N'U'))
BEGIN
       RAISERROR(......)
END
ELSE
BEGIN
--rest of flow
END
GO

Problem

i want to handle error if any table is deleted from the database situation is like - ``` ALTER procedure ABC as begin tran tansinsert insert into table1 values (1,2,3) if @@error <> 0 begin rollback tran tansinsert end else begin commit tran tansinsert end ``` if i am running this proc and table 'table1 ' was not in database than how i will get error message

Original source