0

I have some code I've written that creates a number of temp tables, and I'm trying to check that the temp tables don't exist before I create them.

Currently, the code uses SqlConnection.GetSchema to look for the tables, but that doesn't seem to return temp tables.

Does anyone know of a clean way I can do this, apart from querying tempdb or trying to query the table and looking for exceptions?

  • In a nut shell execute `SELECT OBJECT_ID('tempdb..#YourTempTableName')`, if the result is not `DBNull.Value` then the table exists, otherwise it does not. – Igor Oct 27 '17 at 18:33
  • I was looking for a way to do this in pure C#, similar to `GetSchema`. However, that will work if there's no better way. – Julian Goldsmith Oct 27 '17 at 19:08

0 Answers0