SQL 쿼리로 특정 데이터베이스의 모든 테이블 이름을 가져오시겠습니까?
"MySQL"이나 "MS SQL Server"와 같은 여러 데이터베이스 서버를 처리할 수 있는 애플리케이션을 개발하고 있습니다.
모든 데이터베이스 유형에 적합한 일반 쿼리를 사용하여 특정 데이터베이스의 테이블 이름을 가져오고 싶습니다.다음을 시도했습니다.
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE='BASE TABLE'
그러나 특정 서버의 모든 데이터베이스의 테이블 이름을 제공하지만 선택한 데이터베이스의 테이블 이름만 가져오고 싶습니다.이 쿼리를 제한하여 특정 데이터베이스의 테이블을 가져오려면 어떻게 해야 합니까?
아마도 sql dbms가 스키마를 처리하는 방식이 다르기 때문일 것입니다.
다음을 시도합니다.
SQL Server의 경우:
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG='dbName'
MySQL의 경우:
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA='dbName'
Oracle의 경우 다음과 같은 기능을 사용할 수 있습니다.DBA_TABLES.
여기서 도난당한 경우:
USE YOURDBNAME
GO
SELECT *
FROM sys.Tables
GO
다음 쿼리는 모든 항목을 선택합니다.Tables라고 하는 이름의 데이터베이스에서DBName:
USE DBName
GO
SELECT *
FROM sys.Tables
GO
그냥 넣어주세요DATABASE NAME앞에INFORMATION_SCHEMA.TABLES:
select table_name from YOUR_DATABASE.INFORMATION_SCHEMA.TABLES where TABLE_TYPE = 'BASE TABLE'
USE DBName;
SELECT * FROM sys.Tables;
우리는 없어도 된다GO대신 세미콜론을 사용할 수 있습니다.;.
mysql에서 다음을 사용합니다.
SHOW TABLES;
다음을 사용하여 DB를 선택한 후
USE db_name
"use" 키워드를 사용하지 않고 특정 데이터베이스 내의 모든 테이블을 나열하려면 다음 절차를 수행합니다.
SELECT TABLE_NAME FROM databasename.INFORMATION_SCHEMA.TABLES
이 동작은 양호합니다.
정보_schema.tables에서 * 를 선택합니다.
나는 이 대답을 보지 못했지만, 이봐, 내가 하는 일은 이거야.
SELECT name FROM databaseName.sys.Tables;
아래에서 데이터베이스 쿼리를 선택하려면:
use DatabaseName
지금이다
SELECT * FROM INFORMATION_SCHEMA.TABLES
이제 콘솔에서 작성된 테이블을 볼 수 있습니다.
PFA.
Mysql은 간단하게 할 수 있습니다.표 표시
select * from sys.tables
order by schema_id --comments: order by 'schema_id' to get the 'tables' in 'object explorer order'
go
아래 Oracle DB(PL/SQL)에서는 DB에 존재하는 모든 테이블의 목록을 가져옵니다.
select * from tab;
그리고.
select table_name from tabs;
둘 다 효과가 있어요네 것을 찾아보자.
SELECT TABLE_NAME
FROM your_database_name.INFORMATION_SCHEMA.TABLES
ORDER BY TABLE_NAME;
Exec sp_MSforeachtable 'Select ''?'''
USE dbName;
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE (TABLE_SCHEMA = 'dbName' OR TABLE_SCHEMA = 'schemaName')
ORDER BY TABLE_NAME
If you are working with multiple schemata on an MS SQL server, then SELECT-ing TABLE_NAME without also simultaneously selecting TABLE_SCHEMA might be of limited benefit, so I have assumed we are interested in the tables belonging to a known schema when using MS SQL Server.
I have tested the query above with SQL Server Management Studio using an SQL Server database of mine and with MySQL Workbench using a MySQL database, and in both cases it gives the table names.
The query bodges Michael Baylon's two different queries into one that can then run on either database type. The first part of the WHERE clause works on MySQL databases and the second part (after the OR) works on MS SQL Server databases. It is ugly and logically a little incorrect as it supposes that there is no undesired schema with the same name as the database. This might help someone who is looking for one single query that can run on either database server.
UPDATE FOR THE LATEST VERSION OF MSSQL SERVER (17.7)
SELECT name FROM sys.Tables WHERE type_desc = 'USER_TABLE'
또는SELECT *모든 열을 가져옵니다.
Yes oracle is :
select * from user_tables
즉, 로그인한 사용자만 개체를 소유할 경우user/schema그렇지 않으면all_tables또는dba_tables여기에는 시스템 테이블이 포함됩니다.
Building from Michael Baylon's answer, I needed a list which also included schema information and this is how I modified his query.
SELECT TABLE_SCHEMA + '.' + TABLE_NAME as 'Schema.Table'
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_CATALOG = 'dbName'
ORDER BY TABLE_SCHEMA, TABLE_NAME
Simply get all improtanat information with this below SQL in Mysql
SELECT t.TABLE_NAME , t.ENGINE , t.TABLE_ROWS ,t.AVG_ROW_LENGTH,
t.INDEX_LENGTH FROM
INFORMATION_SCHEMA.TABLES as t where t.TABLE_SCHEMA = 'YOURTABLENAMEHERE'
order by t.TABLE_NAME ASC limit 10000;
SELECT TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE TABLE_TYPE = 'BASE TABLE'
ORDER BY TABLE_NAME
for postgres it will be:
SELECT table_name
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'your_schema' -- probably public
ReferenceURL : https://stackoverflow.com/questions/3913620/get-all-table-names-of-a-particular-database-by-sql-query
'source' 카테고리의 다른 글
| 라벨 요소 안에 입력 요소를 넣어야 합니까? (0) | 2023.04.08 |
|---|---|
| PowerShell Set-Content와 Out-File의 차이점은 무엇입니까? (0) | 2023.04.08 |
| node.js 앱에서 exe 파일을 만드는 방법 (0) | 2023.04.08 |
| Path.absolute를 상대 경로 문자열과 결합합니다. (0) | 2023.04.08 |
| Select Unique와 Select Distinguish의 차이 (0) | 2023.04.08 |
