Search code examples
c#smo

Checking for and dropping an existing table via C# and SMO


I am trying to look for a SQL table by name and if it exists drop it. This all needs to be done in C# using SMO.

To complicate it a bit more the table also has a schema other then "dbo".

Ultimatly the table will be recreated via SMO (I have this working) but I have to make sure it is not there before I can recreate it.

All of the examples that I have seen seem to be creating and then dropping the table all in the same context. In my case the table will have been created and populated in a previous session.


Solution

  • First question is, why can you not drop and recreate with DDL?

    And in answer to your question:

    Table table = new Table(myDatabase, "MyTable", "MySchema");