Check if a SQL table exists

后端 未结 9 2345
北海茫月
北海茫月 2020-12-01 06:30

What\'s the best way to check if a table exists in a Sql database in a database independant way?

I came up with:

   bool exists;
   const string sql         


        
9条回答
  •  半阙折子戏
    2020-12-01 06:48

    Very Simple

    use YOUR_DATABASE --OPTIONAL
    SELECT count(*) as Exist from INFORMATION_SCHEMA.TABLES where table_name = 'YOUR_TABLE_NAME'
    

    If the answer is 1, There is a table. If the answer is 0, There is no table.

提交回复
热议问题