![]() As you’ve already observed, when we ask MySQL to list its tables, the results themselves are presented in a tabular form, and the column which contains the table name is called “Tables_in_”. Similarly, you can filter your results using a WHERE clause. Filtering the results with a WHERE clause For instance, running show tables LIKE 'stu%' returns the student table and the student_onlyname view, but not the teachers table. You can use the LIKE clause to filter the results, in the same way, you’d do in a SELECT statement. You often don’t want to get all of the existing tables, but a subset of them. + -+-+ Code language: SQL (Structured Query Language) ( sql ) Filtering the results with a LIKE clause The command above returns the following output, which distinguishes between “base table” and “view”. For that, you can use a different command: SHOW full tables Code language: SQL (Structured Query Language) ( sql ) However, there’s no way to distinguish the view from the table. Now, run show tables again, and you’ll see that the view is included. First, run the following command to create a view: CREATE VIEW students_onlyname AS SELECT name FROM students Code language: SQL (Structured Query Language) ( sql ) How to tell tables and views apartĭoes the SHOW tables command also show views? Despite the name, yes. ![]() Now we’re ready to proceed to more interesting examples. You’ve just seen the most basic way you can use the show tables command. + -+ Code language: SQL (Structured Query Language) ( sql ) MySQL SHOW tables: some practical examples You should see the tables being listed: + -+ Id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,Įmail VARCHAR( 100)) Code language: SQL (Structured Query Language) ( sql ) In the CoderPad MySQL sandbox, let’s create two tables: CREATE TABLE students ( So, there’s an opportunity to automate some tasks that simply wouldn’t be possible using a GUI. When using it, you can leverage clauses such as WHERE and LIKE to further filter the output.įinally, since this is a command, you can use it in scripts. Also, keep in mind that this command is super flexible. If the command line is all you have, show tables comes in handy. But what are the uses cases for it? After all, when using a MySQL GUI (graphical user interface) client, you can easily display the tables inside a database, typically in a tree.įirst, you won’t always have access to a GUI when interacting with MySQL. That’s pretty much it when it comes to defining the command. ![]() In MySQL, the show tables command is what you use to list the tables in a database. Also, you should have access to a MySQL local installation.Ī great way to do that is to use the CoderPad MySQL Sandbox to quickly and easily get started writing SQL as it’ll be your MySQL client for this article. First, I expect some basic MySQL and SQL knowledge. There are only two prerequisites if you want to follow along with the examples I’ll give. We’ll also cover how listing tables in MySQL compare with other RDBMSs (relational database management systems.) An alternative way to list the tables in a database without using the show tables command.Why it’s useful in the first place, and.The MySQL SHOW tables command is very appropriately named since it allows you to list tables on a MySQL database.īy the end of the post, you’ll have learned: ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |