Skip to content
86 changes: 85 additions & 1 deletion docs/sql-ref-syntax-aux-show-tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,89 @@ license: |
See the License for the specific language governing permissions and
limitations under the License.
---
### Description

**This page is under construction**
The `SHOW TABLES` statement returns all the tables for an optionally specified database.
Additionally, the output of this statement may be filtered by an optional matching
pattern. If no database is specified then the tables are returned from the
current database.

### Syntax
{% highlight sql %}
SHOW TABLES [{FROM|IN} database_name] [LIKE 'regex_pattern']
{% endhighlight %}

### Parameters
<dl>
<dt><code><em>{FROM|IN} database_name</em></code></dt>
<dd>
Specifies the `database` name from which tables are listed.
</dd>
<dt><code><em>LIKE 'regex_pattern'</em></code></dt>
<dd>
Specifies the regular expression pattern that is used to filter out unwanted tables.
<ul>
<li> Except `*` and `|` characters remaining characters will follow the regular expression convention.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Except for * and |, the pattern works like a regex"

<li> `*` matches 0 or more characters and `|` used to provide more than one regex with OR condition. </li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"* alone matches 0 or more characters, and | is used to separate multiple different regexes, any of which can match"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comments handled
Thanks for reviewing

<li> The leading and trailing blanks are trimmed in the input pattern before processing.</li>
</ul>

</dd>
</dl>

### Example
{% highlight sql %}
-- List all tables in default database
SHOW TABLES;
+-----------+------------+--------------+--+
Copy link
Contributor

@dilipbiswal dilipbiswal Sep 21, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please lets fix the formatting. Did we construct this output by hand ? Can we paste the
actual output here please so we preserve the formatting.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dilipbiswal
I just Copy and paste the actual output from the Beeline console
Here is the beeline console snap
image

In the UI it looks like below, i think it is normal
image

Only in the git file editor, it shows inconsistent.

| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
| default | suj | false |
+-----------+------------+--------------+--+

-- List all tables from userdb database
SHOW TABLES FROM userdb;
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| userdb | user1 | false |
| userdb | user2 | false |
+-----------+------------+--------------+--+

-- List all tables in userdb database
SHOW TABLES IN userdb;
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| userdb | user1 | false |
| userdb | user2 | false |
+-----------+------------+--------------+--+

-- List all tables from default database matching the pattern `sam*`
SHOW TABLES FROM default LIKE 'sam*';
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
+-----------+------------+--------------+--+

-- List all tables matching the pattern `sam*|suj`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: can we have a line between previous test and this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dilipbiswal
Done, updated the snap's also.

SHOW TABLES LIKE 'sam*|suj';
+-----------+------------+--------------+--+
| database | tableName | isTemporary |
+-----------+------------+--------------+--+
| default | sam | false |
| default | sam1 | false |
| default | suj | false |
+-----------+------------+--------------+--+

{% endhighlight %}

### Related statements
- [CREATE TABLE](sql-ref-syntax-ddl-create-table.html)
- [DROP TABLE](sql-ref-syntax-ddl-drop-table.html)
- [CREATE DATABASE](sql-ref-syntax-ddl-create-database.html)
- [DROP DATABASE](sql-ref-syntax-ddl-drop-database.html)