SQL- Show Tables

SQL-SHOW TABLES

SQL- Show Tables

Databases లో ఎన్ని tables create చేసారో, అవి actual గా database లో ఉన్నాయా లేదా అన్నది మనం ఎలాగె తెలుసుకుంటాం? SQL లో దానికి ఓ powerful command ఉంది – SHOW TABLES.

ఈ lesson లో మనం SHOW TABLES command ని ఎలా ఉపయోగించాలో, దాని syntax, examples, మరియు real-time usage గురించి తెలుసుకుంటాం.

SHOW TABLES Command Overview

SQL లో, SHOW TABLES అనే command ను మనం ప్రస్తుతం ఉన్న database లో ఉన్న అన్ని tables names ను retrieve చేయడానికి ఉపయోగిస్తాము.

ఈ command ఉపయోగించి:

  • మీరు create చేసిన tables ను చూడొచ్చు
  • Mistaken గా duplicate గా create చేసిన tables ఉన్నాయా అని తెలుసుకోవచ్చు
  • ఏ database లో ఏ tables ఉన్నాయో చూడొచ్చు

గమనిక: మీరు SHOW TABLES command వాడేముందు, ఏ database ని use చేయాలనుకుంటున్నారో USE database_name; ద్వారా set చేసుకోవాలి.

Syntax

SQL
SHOW TABLES;

ఈ command పైగా చాలా సింపుల్.

Optional: Specific Pattern తో చూడాలంటే

SQL
SHOW TABLES LIKE 'pattern%';

ఇది wildcard pattern ఉపయోగించి matching tables names మాత్రమే చూపిస్తుంది.

Example 1: Show All Tables

SQL
USE mydatabase;
SHOW TABLES;

అందులో output ఇలా ఉంటుంది:

+------------------+
| Tables_in_mydatabase |
+------------------+
| customers         |
| employees         |
| orders            |
| products          |
+------------------+

ఇది mydatabase అనే database లో ఉన్న అన్ని tables ను చూపిస్తుంది.

Example 2: Filter Using LIKE

SQL
SHOW TABLES LIKE 'cust%';

అంటే 'cust' అనే prefix తో మొదలయ్యే tables names ను మాత్రమే చూపిస్తుంది. Output:

+------------------+
| Tables_in_mydatabase |
+------------------+
| customers         |
| customer_orders   |
+------------------+

Practical Use Case:

ఒక developer లేదా DBA (Database Administrator) గా మీరు ఒక legacy project లో join అయినప్పుడు, ముందు దానిలో ఉన్న అన్ని tables structure తెలుసుకోవాలి. మొదట చేసే step ఏమిటంటే:

SQL
USE legacy_project_db;
SHOW TABLES;

ఈ step ద్వారా మీరు database లో ఉన్న మొత్తం tables names ని పొందవచ్చు.

Difference Between SHOW TABLES vs SELECT:

  • SHOW TABLES → structure view, available tables ఏవో తెలుసుకోవడానికి
  • SELECT → tables లో actual data retrieve చేయడానికి

అంటే, SHOW TABLES command structure పై focus చేస్తుంది, content పై కాదు.

Common Errors:

  1. No database selected error:ERROR 1046 (3D000): No database selected→ మీరు USE database_name; చేయకుండా SHOW TABLES; అన్నప్పుడు వస్తుంది.
  2. Permission error: మీ user కి full privileges లేకపోతే SHOW TABLES పనిచేయదు.

Advanced Tip: Combine With Information Schema

SQL
SELECT table_name FROM information_schema.tables WHERE table_schema = 'mydatabase';

ఇది కూడా SHOW TABLES command కి alternative గా పనిచేస్తుంది, special conditions పెట్టుకోవాలంటే use చేస్తారు.

Practice Tasks:

  1. మీ SQL Server లో ఒక కొత్త database create చేసి అందులో రెండు tables create చేయండి. తర్వాత SHOW TABLES వాడి వాటిని చూపించండి.
  2. ఒక existing database లో LIKE keyword ఉపయోగించి orders తో ప్రారంభమయ్యే tables చూపించండి.
  3. information_schema.tables approach ఉపయోగించి మీ current database లోని tables retrieve చేయండి.

Leave a Reply

Your email address will not be published. Required fields are marked *