I want to write a query for MS SQL Server that adds a column into a table. But I don't want any error display, when I run/execute the following query.
I am using this sort of query to add a table ...
IF EXISTS (
SELECT *
FROM sys.objects
WHERE OBJECT_ID = OBJECT_ID(N'[dbo].[Person]')
AND TYPE IN (N'U')
)
But I don't know how to write this query for a column.
sys.tablesinstead of the "generic"sys.objects- then you don't have to specify the type explicitly (it's obvious from thesys.tablesalready....) - marc_sIF NOT EXISTSclause to theADD COLUMNsyntax) - Brondahl