일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
- java
- 나도코딩
- 스프링 부트 3
- Wildcard
- cluster index
- 티스토리챌린지
- types
- Functional Interfaces
- Proxy Object
- entrySet
- literal
- noncluster index
- HashMap
- 혼공컴운
- 0 시작
- Interface
- 자율학습
- 인프런
- Lazy loading
- 혼공학습단
- Access Modifier
- dotnet
- Spring Data JPA
- 접근 제어자
- 혼공
- 오블완
- 인터페이스
- 혼공자바
- 접근제어자
- 네트워크
- Today
- Total
지금을 사는 사람
[MySQL] mysql에서 사용 가능한 데이터 타입 본문
Certainly! Let's combine the explanations and examples for Enumerated and Set Types, as well as Spatial Data Types, with the previous answer:
INT (Integer):
Description: A standard integer data type that stores whole numbers without decimal places.
Example:
CREATE TABLE example_int ( user_id INT, age INT );
BIGINT:
Description: Similar to INT but with a larger range, suitable for storing extremely large whole numbers.
Example:
CREATE TABLE example_bigint ( transaction_id BIGINT, account_balance BIGINT );
FLOAT:
Description: A floating-point number with single-precision, suitable for decimals but with a limited precision.
Example:
CREATE TABLE example_float ( temperature FLOAT, weight FLOAT );
DOUBLE:
Description: Similar to FLOAT but with double-precision, providing higher precision for decimal values.
Example:
CREATE TABLE example_double ( latitude DOUBLE, longitude DOUBLE );
VARCHAR (Variable-Length Character):
Description: A variable-length string type that can store alphanumeric characters up to a specified length.
Example:
CREATE TABLE example_varchar ( first_name VARCHAR(50), last_name VARCHAR(50) );
CHAR (Fixed-Length Character):
Description: A fixed-length string type that pads shorter strings with spaces to match the defined length.
Example:
CREATE TABLE example_char ( country_code CHAR(3), airline_code CHAR(2) );
TEXT:
Description: A data type for storing large amounts of text data, suitable for longer strings or documents.
Example:
CREATE TABLE example_text ( article TEXT, description TEXT );
DATE:
Description: Stores a date in the format 'YYYY-MM-DD'.
Example:
CREATE TABLE example_date ( event_date DATE, birth_date DATE );
TIME:
Description: Represents a time of day in the format 'HH:MM:SS'.
Example:
CREATE TABLE example_time ( start_time TIME, end_time TIME );
DATETIME:
Description: Combines date and time, representing a specific point in time with higher precision.
Example:
CREATE TABLE example_datetime ( log_timestamp DATETIME, event_datetime DATETIME );
TIMESTAMP:
Description: Similar to DATETIME but with automatic updating to the current timestamp when a record is inserted or updated.
Example:
CREATE TABLE example_timestamp ( record_created TIMESTAMP, last_updated TIMESTAMP );
ENUM (Enumerated Type):
Description: ENUM is a data type that allows you to define a list of permissible values for a column. It restricts the column to only one of the predefined set values.
Example:
CREATE TABLE example_enum ( status ENUM('active', 'inactive', 'pending') );
In this example, the
example_enum
table has a columnstatus
that can only take values 'active', 'inactive', or 'pending'.
SET Type:
Description: Similar to ENUM, SET is a data type that allows you to define a list of permissible values for a column. However, SET columns can have multiple values selected from the predefined set.
Example:
CREATE TABLE example_set ( features SET('wifi', 'bluetooth', 'gps', 'camera') );
Here, the
example_set
table has a columnfeatures
that can have multiple values selected from the set ('wifi', 'bluetooth', 'gps', 'camera').
Spatial Data Types:
Description: Spatial data types in MySQL are used for storing and querying geometric or geographic data. Common types include POINT, LINESTRING, POLYGON, and GEOMETRY.
Example with POINT:
CREATE TABLE example_spatial ( location POINT );
In this example, the
example_spatial
table has a columnlocation
using the POINT data type to store specific spatial coordinates.Example with GEOMETRY:
CREATE TABLE example_geometry ( shape GEOMETRY );
Here, the
example_geometry
table has a columnshape
using the GEOMETRY data type, which can store various types of spatial data like points, lines, or polygons.
'CS > 데이터베이스' 카테고리의 다른 글
데이터 베이스 모델링 : ERD 연습 (1) | 2024.01.25 |
---|---|
클러스터 인덱스, 논클러스터 인덱스 (0) | 2024.01.25 |