Sql check if table exists MySQL – 5 Ways to check if a Table exists in Sql Server?

Sql check if table exists MySQL – SQL Query. The sql query to check if the table with a given name is present in the database or not, Check IF (NOT) Exists in SQL Server.

Sql check if table exists MySQL

To check if a table exists in SQL Server, you can use the INFORMATION_SCHEMA. This Article looks at how to check if a table exists in the sql database.

Example : 1 Using INFORMATION_SCHEMA

To check if a table exists use:

IF (EXISTS (SELECT * 
                 FROM INFORMATION_SCHEMA.TABLES 
                 WHERE TABLE_SCHEMA = 'TheSchema' 
                 AND  TABLE_NAME = 'Pakainfo_v1'))
BEGIN
    --Do Stuff
END

SQL Check if table exists

IF (EXISTS (SELECT *
   FROM INFORMATION_SCHEMA.TABLES
   WHERE TABLE_SCHEMA = 'dbo'
   AND TABLE_NAME = 'Pakainfo_v1'))
   BEGIN
      PRINT 'Your DB Table Exists'
   END;
ELSE
   BEGIN
      PRINT 'No Table in db'
   END;

Result:
Your DB Table Exists

Don’t Miss : SQL Check If Table Exists

Read Also:  jQuery AJAX file Image upload PHP Example

Example 2: Using OBJECT_ID() function

IF OBJECT_ID('model.dbo.Pakainfo_v1') IS NOT NULL
   BEGIN
      PRINT 'Your DB Table Exists'
   END;
ELSE
   BEGIN
      PRINT 'No Table in db'
   END;

Result:

Your DB Table Exists

I hope you get an idea about Sql check if table exists MySQL.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.