programing

mysql 테이블에서 열 크기를 가져오는 방법

itsource 2023. 8. 15. 20:14
반응형

mysql 테이블에서 열 크기를 가져오는 방법

테이블 안에 있는 열 하나의 정확한 크기를 찾고 있습니다.PHMyAdmin은 열 크기를 표시하지 않고 테이블만 표시합니다.

기둥의 크기를 알 수 있는 방법이 있습니까?

감사해요.

컬럼의 크기를 알고 싶다면 =테이블 =의 COLUMN_NAMETABLE_NAME, 다음과 같은 쿼리를 항상 실행할 수 있습니다.

SELECT sum(char_length(COLUMN_NAME)) 
FROM TABLE_NAME;

반환되는 크기(바이트)입니다.kb 단위로 원하는 경우 다음과 같이 1024로 나눌 수 있습니다.

SELECT sum(char_length(COLUMN_NAME))/1024 
FROM TABLE_NAME;
SELECT column_name, 
       character_maximum_length 
FROM   information_schema.columns 
WHERE  table_schema = Database() 
       AND -- name of your database 
       table_name = 'turno' 
       AND -- name of your table 
       column_name = 'nombreTurno' -- name of the column 

정보_SCHEMA.

전체 테이블 크기를 원한다면 이것을 사용합니다.

SELECT table_name                                                 AS "Tables", 
       Round(( ( data_length + index_length ) / 1024 / 1024 ), 2) "Size in MB" 
FROM   information_schema.tables 
WHERE  table_schema = "$db_name" 
ORDER  BY ( data_length + index_length ) DESC; 

편집

SELECT column_name, 
       character_maximum_length 
FROM   information_schema.columns 
WHERE  table_schema = 'websi_db1' 
       AND table_name = 'thread' 
       AND column_name = 'title' 

원천

스크립트에서 이 작업을 수행하는 경우 연결을 설정한 후에 이 작업을 실행할 수 있습니다(따라서 데이터베이스가 이미 선택되어 있음).

SELECT  character_maximum_length
FROM information_schema.columns
WHERE table_name = ? AND column_name = ?

?'s를 테이블 이름과 열의 이름으로 각각 바꿉니다.

언급URL : https://stackoverflow.com/questions/21772205/how-to-get-size-of-column-in-mysql-table

반응형