OpenLampTech

Share this post

MySQL SHOW TABLES - 2 variations

openlamptech.substack.com

MySQL SHOW TABLES - 2 variations

Learn two variations of the MySQL SHOW TABLES command

Joshua Otwell
Feb 1, 2022
Share this post

MySQL SHOW TABLES - 2 variations

openlamptech.substack.com

This post is an excerpt from one of my premium MySQL Beginner blog posts and content.

If you are new to MySQL and want to learn how to use the database and get the data you need from it, I am making these premium posts and content for you!


Thanks for reading OpenLampTech! Subscribe to the free weekly newsletter for all the great original and curated PHP/MySQL content I share in the publication.


SHOW TABLES Command

In order to SELECT any data, we have to know what table we want to see the data from. Therefore, we need to know the table name.

We can use the SHOW TABLES command and retrieve a result set containing the tables which are present in a database. There are 2 variations of SHOW TABLES, both of which return the same information:

  1. SHOW TABLES;

  2. SHOW TABLES IN database_name; (where database_name is the name of the database)

Let's see an example of each so we are familiar with them both and can use either seamlessly if needed.

SHOW TABLES

In MySQL Workbench, on the first line of the .sql script we are using to execute the MySQL commands, we simply write USE sakila; as shown in this screenshot:

USE sakila (database command)

When you execute USE database_name, you're instructing MySQL that the subsequent queries should be run against the named database. We can use SHOW TABLES; on the next line:

USE sakila and SHOW TABLES commands together.

Executing SHOW TABLES; returns a result set with all of the table names for the tables that are part of the sakila database that an authenticated user has permission to see:

Results for SHOW TABLES command.


Do you need to learn MySQL? Just starting and confused about how to query a table and get the data you need? I am creating premium MySQL Beginners content for this specific reason. To help those who want to learn the basics of MySQL but don't know where to start. Learn more about my premium MySQL blog posts and content as I develop and release them.

Tell me more!


SHOW TABLES IN database_name

In the event that you haven't issued the USE statement, you can specify the named database when you execute the SHOW TABLES command:

Using SHOW TABLES IN sakila command.

Executing this form of SHOW TABLES has the same effect, returning a result set of table names in the named database:

A listing of all tables in the sakila database from the SHOW TABLES IN DB command.

Visit my blog Digital Owl’s Prose, where I write regularly on CodeIgniter, PHP, and SQL. I’m also active on Medium, LinkedIn, Twitter, and Instagram.


How can I help you?
  • Are you thinking of starting up a blog? I use WordPress for my blog, Digital Owl’s Prose. Let’s both save money on the plans offered. 💸

  • Grab a Gmail HTML Email Signature template from my Etsy shop and make your emails pop and stand out. ✉️

  • Need hosting for your next web application or WordPress site? I use and highly recommend Hostinger. They have great pricing and service.

  • I enjoy reading Refind: The essence of the web, every morning in your inbox. Subscribe for free. Help me get a premium subscription by signing up yourself with my referral link.

  • Grab a free pack of mobile Creator wallpapers with my referral link.

  • Just getting started or wanting to learn MySQL? Find out about my premium blog posts and MySQL Beginner Series here.


Want to support this newsletter and my work? Drop some spare change in my Tip Jar.💰

Tip Jar

Disclosure: Some of the services and products links in this email are affiliate links. At no additional cost to you, should you make a purchase by clicking through one of them, I will receive a commission.

Cover image credits: Image by Clker-Free-Vector-Images from Pixabay

Share this post

MySQL SHOW TABLES - 2 variations

openlamptech.substack.com
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Joshua Otwell
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing