본문 바로가기

Programming/Database

Difference between Char and Varchar in Database datatype, 데이터베이스 자료형 Varchar 와 Char 의 차이점


Difference between Char and Varchar in Database datatype, 

데이터베이스 자료형 Varchar 와 Char 의 차이점




I got this article from ( here )


원문보기 ( here )




Difference Between Char and Varchar



Difference between Char and Varchar



Data Type


‘Char’ is a fixed-length data type which is used to store character string value of fixed length, whereas ‘Varchar’ is a variable-length data type which is used to store variable length alphanumeric data.


'Char' 은 고정된 길이의 스트링 값이 저장하는데 사용되는 고정된 길이의 데이터 타입인데, 

'Varchar' 은 가변 길이의 alphanumeric data를 저장하는데 사용되는 가변 길이 데이터 타입이다.



Storage Size


The storage size of the character value is equal to the maximum size of this column that you declare while creating the table. On the other hand, the storage size of the varchar value is the actual length of the data entered, not the maximum size for this column.


 'Char' 값의 최대 저장 공간 크기는 table을 만들때 선언한 최대의 컬럼 저장공간 크기인 반면에, 'Varchar' 값의 최대 저장공간 크기는 들어온 데이터의 실제 길이이고, 컬럼의 최대 사이즈가 아니다.



Data Entries


You can use char when the data entries in a column are expected to be the same size, while on the contrary, varchar can be used when the data entries in a column are expected to vary in size.


'Char' 은 컬럼 안에 들어오는 데이터 엔트리가 다 같은 사이즈 일때 사용할수 있다.

'Varchar' 은 반면에, 다양한 사이즈의 데이터 엔트리가 들어올때 사용될 수 있다.



Memory Allocation


Char uses static memory allocation while varchar uses dynamic memory allocation


'Char' 은 정적인 메모리 할당을 사용하고, 'Varchar' 은 동적 메모리 할당을 사용한다.



Length


The length of a char variable can be of any value from 0 to 255, while the length of varchar variable ranges from 0 to 65,535.


'Char' 변수의 길이는 0~ 255 어느 길이든 될 수 있고, 반면에

'Varchar' 의 변수 길이 범위는 0~ 65535 까지 될 수 있다.



Application


Data entries are consistent in char which is used for storing data like phone numbers, whereas varchar is used for storing varying data like addresses.


'Char' 의 저장 데이터는 전화번호와 같은 변하지 않는 데이터 엔트리가 쓰이고, 반면에

'Varchar' 은 주소와 같은 다양한 저장 데이터에 사용된다.





To sum up


요약정리


Both ‘Char’ and ‘Varchar’ are data types in programming languages and database systems that share some common traits in terms of functionality and technicality. However, they differ considerably like the way they are stored and retrieved.


'Char' 와 'Varchar' 은 모두 데이터베이스 시스템과 프로그래밍 언어에서 사용되는 데이터타입이고, 몇몇의 기능적이고 기술적인 공통의 특성을 가진다. 그러나 저장되는 방식과 가져오는 방식에서 상당히 다르다.



While char actually refers to character, varchar refers to variable character. As the name suggests, char is a fixed-length data type while varchar is a variable-length data type.


'Char' 은 character 을 지칭하고, 'Varchar' 은 variable character 을 지칭한다. 이름이 말하듯, 

'Char' 은 고정길이 데이터타입이고, 'Varchar' 은 가변길이 데이터타입이다.



Char takes up to 1 byte per character, whereas varchar also takes up to 1 byte per character plus extra 1 or 2 bytes to store length information. For char, the length varies from 0 to 255 and for varchar, it can be anything between 0 and 65,535.


'Char' 은 character 마다 1byte를 차지하고, 'Varchar' 은 똑같이 character 마다 1byte를 차지하면서 추가로 1~ 2bytes 의 길이 정보를 저장한다. 'Char' 은 0~ 255의 길이이고,

'Varchar' 은 0~ 65535 의 길이이다.



As char is fixed-length, any remaining space in the field is padded with blanks. Varchar, on the other hand, is variable-length so it holds only the characters you assign to it.


'Char' 은 고정길이이기 때문에, 남아있는 공간들은 블랭크로 채워진다.

'Varchar' 은 가변길이이기 때문에, 네가 넣어둔 characters 만큼만 사용한다(공간을)



Remaining characters are padded with white spaces when the values are stored in ‘char’ fields, whereas ‘varchar’ doesn’t add extra spaces when you provide the less data than specified length.


'Char' 은 스페이스로 나머지 고정길이 나머지 공간이 채워지고

'Varchar' 은 사용한 문자의 특정 길이보다 추가의 공간을 사용하지 않는다.




그래서

'Char' 은 전화번호, 아이피, 우편번호 등 딱 고정된 폼에서 사용하는 문자를 저장하면 되겠고,

'Varchar' 은 주소전체, 물품이름 등 가변의 글자길이 폼에서 사용하는 문자를 저장하면 되겠다




Something else....




2018/11/02 - [Programming/Java] - Apache POI library excel file read to make Mat in openCV / 아파치 POI 라이브러리 엑셀파일 읽기 OpenCV Mat 만들기 (java, c++)



2018/11/01 - [Programming/Java] - Java Math class - squareRoot, power num example / 자바 - 루트, 제곱 값 예제



2018/10/28 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #21 isIPv4Address. Algorithm, 알고리즘, Codefights, CodeSignal, regx, 정규표현식, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/28 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #20 arrayMaximalAdjacentDifference. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar

2018/10/27 - [Algorithm/Code Fights (Code Signal)] - Aracade Intro #19 AreEquallyStrong. Algorithm, Codefights, CodeSignal, 코드파이트, 코드시그널, c++ java c# scalar



2018/10/26 - [Programming/Java] - Difference between String, StringBuilder, and StringBuffer Class 차이점 / Java c++ 문자열, example 예제



2018/10/25 - [Programming/Image Processing] - Complex number matrix division, multiply in OpenCv like Matlab (실수부와 복소수허수부 포함된 매트릭스 곱셈, 나눗셈)