Jak wyświetlić wszystkie tabele z bazy danych w SQL?

Jak wyświetlić wszystkie tabele z bazy danych w SQL?

7 marca, 2023 Wyłączono przez admin

Różne bazy danych mają różne widoki systemowe lub katalogi, aby wyświetlić listę wszystkich tabel w bazie danych. Zobaczmy kilka sposobów na sprawdzenie tego w kilku systemach baz danych.

SQL SERVER:

W SQL Server mamy cztery różne sposoby na wypisanie wszystkich tabel w bazie danych.

SELECT table_name
FROM INFORMATION_SCHEMA.TABLES
WHERE table_type = 'BASE TABLE'

SELECT name
FROM sys.tables

SELECT name
FROM sysobjects
WHERE xtype = 'U'

SELECT name
FROM sys.objects
WHERE type_desc = 'USER_TABLE'

Oracle:

W Oracle mamy trzy różne sposoby na wypisanie wszystkich tabel w bazie danych.

-- This returns all the tables in the database system.
SELECT table_name
FROM dba_tables

-- This returns all the tables which are accessible to the current user
SELECT table_name
FROM all_tables

-- This returns all the tables which are created by the current user
SELECT table_name
FROM user_tables

MySQL

W MySQL możemy użyć poniższego zapytania, aby wyświetlić listę wszystkich tabel w serwerze.

-- Lists all the tables in all databases
SELECT table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE'

-- Lists all the tables in a particular database
SELECT table_name
FROM information_schema.tables
WHERE table_type='BASE TABLE'
      AND table_schema = 'your_database_name'