본문 바로가기

programming

[DB] CREATE 로 테이블 만들고 INSERT 해보기

create database playground;

use playground;

 

CREATE TABLE swimming_pool (
	idx int NOT NULL AUTO_INCREMENT COMMENT '수영장 고유번호',
    title varchar(20) NOT NULL COMMENT '수영장 이름',
    type tinyint unsigned DEFAULT 0 COMMENT '수영장 타입 0:국공립, 1:사설',
    sido varchar(30) DEFAULT NULL COMMENT '주소 시/도',
    gugun varchar(30) DEFAULT NULL COMMENT '주소 구/군',
    road_name varchar(30) DEFAULT NULL COMMENT '주소 도로명',
    deatil_juso varchar(30) DEFAULT NULL COMMENT '주소 디테일',
    phone varchar(20) DEFAULT NULL COMMENT '전화번호',
    url varchar(100) DEFAULT NULL COMMENT '홈페이지주소',
    open_time time DEFAULT NULL COMMENT '오픈시간',
    close_time time DEFAULT NULL COMMENT '마감시간',
    close_yn char(1) DEFAULT 'N' COMMENT '폐장 여부 N:아니오(운영중), Y:예(미운영)', -- N/Y 0/1
    lane_length smallint DEFAULT NULL COMMENT '레인 길이',
    lane_count tinyint DEFAULT NULL COMMENT '레인 개수',
    max_depth float DEFAULT NULL COMMENT '최대 수심',
    min_depth float DEFAULT NULL COMMENT '최저 수심',
    kids_pool_yn tinyint DEFAULT NULL COMMENT '키즈풀유무 0:무, 1:유',
    created_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '등록일시',
	updated_at timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '업데이트일시', 
	PRIMARY KEY (idx),
    KEY idx_swimming1 (title),
    KEY idx_swimming2 (sido, gugun, road_name)
    ) ENGINE=InnoDB AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci
    
    -- Y/N 0/1
    -- int , tinyint, smallint
    -- tinyint 정수형으로 총 1byte 저장공간 차지, -128~127 또는 0~255(unsigned)
    -- smallint 정수형 총 2byte 저장공간 차지, -83


select * from swimming_pool;

 

INSERT INTO playground.swimming_pool
(title, type, sido, gugun, road_name, phone, url, open_time, close_time, close_yn, lane_length, lane_count, max_depth, min_depth, kids_pool_yn)
VALUES ('필립발리휘트니스 정자본점', 1, '경기 성남시', '분당구', '내정로 58', '031-728-7777', 'http://www.sportsclubphillip.com/', '06:00:00', '23:00:00', 'N', 25, 5, 2, 1.2, 1);


INSERT INTO playground.swimming_pool
(title, type, sido, gugun, road_name, phone, url, close_yn, lane_length, lane_count, max_depth, min_depth, kids_pool_yn)
VALUES ('올림픽기념국민생활관', 0, '서울', '종로구', '성균관로 91', '02-745-6701', 'http://www.ijongno.co.kr/front/main/11', 'N', 25, 6, 2.5, 1.5, 0);