-3

I want to add an IF/DROP Statement similar so the SQL query will run continuously without manual intervention. I need to make sure when I run the query it runs without interference.

Currently I have - which runs fine, but if I want to run it again - it gives me an error: Instance already exists. I want to have a query that checks this instance, drops it if already exists, and creates it.

ALTER TABLE [dbo].[DATABASE]
ADD [GeoLocation] GEOGRAPHY
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • Please [edit] the title of your question to be more descriptive. If you remove the tag information (SQL), your title is *Programming Statement*, which is absolutely meaningless. Your title should describe the question you're asking or the problem you're experiencing in a way that is meaningful, and that will have relevance to future readers here who find it in a search result. While you're at it, you can edit the body of the question to actually ask one. You've stated what you **WANT** to do, but haven't explained what the problem is with the code you've posted or asked a question of any sort. – Ken White Nov 16 '15 at 04:11
  • Possible duplicate of [How to check if column exists in SQL Server table](http://stackoverflow.com/questions/133031/how-to-check-if-column-exists-in-sql-server-table) – siride Nov 16 '15 at 04:12

1 Answers1

-1
IF( SELECT COUNT(*)
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'TRI_DATA$'
      AND TABLE_SCHEMA = 'dbo'
      AND COLUMN_NAME = 'GeoLocation' ) = 0
ALTER TABLE [dbo].[TRI_DATA$]
ADD [GeoLocation] GEOGRAPHY
japzdivino
  • 1,736
  • 3
  • 17
  • 25
YongZPub
  • 107
  • 2