Add a column to a table, if it does not already exist

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.

7 Answers
7

Leave a Comment