How to check if database table exists when the table has 0 rows?

How to check if database table exists when the table has 0 rows?

EDITED FOLLOWING FEEDBACK.

EDITED FOLLOWING FEEDBACK.

In the following code "exist" should == 1 if the table exists in the database. However, it is returning 0 for me, even though the table exists in the database. I am not sure why this is happening?

Thanks:

foreach (var row in calcSched)
            {
                var dif3 = new DataInterfaceFactory(DatabaseTypes.SqlServer, row.DatabaseName, row.ServerName);
                //var dbName = m_api.Database.ExecuteQuery<CALCULATION_SCHEDULE>("SELECT CONCAT(c.SERVER_NAME, '.', c.DATABASE_NAME)");// concat server name and DB name

            using (DataReader dr2 = dif3.GetDataReader())
            {
                dr2.ExecuteReader("SELECT COUNT(1) AS TABLECOUNT2 FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'dbo' AND TABLE_NAME = 'PMS_CAL_SCHEDULE'");
                var exists = Convert.ToInt32(dr2["TABLECOUNT2"]);
                CommandExecutor CE = dif3.GetCommandExecutor();

                try
                {
                    if (exists == 0)//if table doesn't exist create it
                    {
                        string sql = "CREATE TABLE dbo.PMS_CAL_SCHEDULE(CALCULATION_SCHEDULE_UID INT, USER_UID INT, SCHEDULE_DATE DATE, PMS_CALC_STATUS_UID INT, CALCULATION_START_DATE DATE, CALCULATION_END_DATE DATE, STATUS_MESSAGE CHAR(100), PROGRESS CHAR(20)";
                        CE.ExecuteNonQuery(sql);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error: could not create PMS_CALC_SCHEDULE");
                }
            }
        }


c-sharp sql-server database

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Introduction to Structured Query Language SQL pdf

SQL stands for Structured Query Language. SQL is a scripting language expected to store, control, and inquiry information put away in social databases. The main manifestation of SQL showed up in 1974, when a gathering in IBM built up the principal model of a social database. The primary business social database was discharged by Relational Software later turning out to be Oracle.

Welcome Back the T-SQL Debugger with SQL Complete – SQL Debugger

Debug SQL stored procedures and develop your SQL database project with dbForge SQL Complete, a new add-in for Visual Studio and SSMS. When you develop large chunks of T-SQL code with the help of the SQL Server Management Studio tool, it is essential to test the “Live” behavior of your code by making sure that each small piece of code works fine and being able to allocate any error message that may cause a failure within that code.

The Easy Guide on How to Use Subqueries in SQL Server

This article provides an outlook on various types of subqueries in SQL such as select or other T-SQL statements and caveats when using them.

SQL Server Tutorial For Beginners - Learn MS SQL Server with Examples

SQL Server Tutorial For Beginners, Microsoft SQL Server Tutorial, SQL Server Training. Microsoft SQL Server explains all the fundamentals of MS SQL Server with examples. What is DBMS? What is SQL? What is SQL Server? SQL Server Installation