We help IT Professionals succeed at work.
Get Started

check if table/record exists in mysql

mikha
mikha asked
on
55 Views
Last Modified: 2020-02-04
I want to create scripts to create a database/schema and seed data in mysql as such, pseudo code below

if the table doesn't exits is true
    then create table

Note - I don't want to drop table before  creating it , just want to check if it exits or not ,

another way i was thinking was, which is less code , more like a try and catch block in other languages , such that if there is already a table by that name, it throws an exception and
i don't do anything .

try {

         create table MyTable
      }

Catch {
              //do nothing
   }

Also, if i version these scripts , such that

script 1
script 2
script 3,

is there a way, I can run this and make changes to my database from whatever folder i am in  , instead of having to copy the content of the scripts to the query window in mysql workbench
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2012
Distinguished Expert 2019
Commented:
This problem has been solved!
Unlock 1 Answer and 5 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant

An Experts Exchange subscription includes unlimited access to online courses.

Get Started
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE