⭐SQL Data Manipulation Language (DML)
데이터베이스 예제 프로그래밍
데이터베이스 구축
DROP DATABASE IF EXISTS `gunpladb`;
CREATE DATABASE IF NOT EXISTS `gunpladb`;
USE `gunpladb` ;
CREATE TABLE `mechanic` (
`id` INT NOT NULL AUTO_INCREMENT,
`name` VARCHAR(255) NOT NULL,
`model` VARCHAR(100) NOT NULL,
`manufacturer` VARCHAR(255) NULL,
`armor` VARCHAR(255) NULL,
`height` DECIMAL(7,2) NULL CHECK (height > 0),
`weight` DECIMAL(7,2) NULL,
CONSTRAINT chk_weight CHECK (weight > 0 and weight < 3000),
PRIMARY KEY (`id`)
);
INSERT INTO mechanic (name, model, manufacturer, armor, height, weight) VALUES
('건담', 'RX-78-2', 'Earth Federation', 'Luna Titanium', 18.0, 43.4),
('건캐논', 'RX-77-2', 'Earth Federation', 'Luna Titanium', 17.5, 51.0),
('건탱크', 'RX-75', 'Earth Federation', 'Luna Titanium', 15.0, 56.0),
('짐', 'RGM-79', 'Earth Federation Forces', 'Titanium Alloy', 18.0, 41.2),
('자쿠 II', 'MS-06F', 'Zeonic Company', 'Super Hard Steel Alloy', 17.5, 58.1),
('샤아 전용 자쿠 II', 'MS-06S', 'Zeonic Company', 'Super Hard Steel Alloy', 17.5, 56.5),
('돔', 'MS-09B', 'Zimmad Company', 'Super Hard Steel Alloy', 18.6, 62.6),
('릭 돔', 'MS-09R', 'Zimmad Company', 'Super Hard Steel Alloy', 18.6, 43.8),
('즈고크 E', 'MSM-07E', 'MIP Company', 'Titanium Alloy Ceramic Composite', 18.4, 69.5),
('씨그', 'ZGMF-515', 'Zodiac Alliance of Freedom Treaty', null, 21.43, 80.22),
('거너 자쿠 워리어', 'ZGMF-1000/A1', 'Integrated Design Bureau', null, 20.50, 91.11),
('건담 5호기', 'RX-78-5', 'Earth Federation', 'Luna Titanium', 18.0, 42.9),
('건담 Mk-II', 'RX-178', 'Titans', 'Titanium Alloy Ceramic Composite', 18.5, 33.4),
('겔구그', 'MS-14A/C', 'Zeonic Company', 'Super Hard Steel Alloy', 19.2, 42.1),
('겔구그 예거', 'MS-14Jg', 'Zeonic Company', 'Titanium Alloy Ceramic Composite', 19.2, 40.5),
('고그', 'MSM-03', 'Zimmad Company', 'Super High Tensile Steel', 18.3, 82.4),
('네모', 'MSA-003', 'Anaheim Electronics', 'Gundarium α Alloy', 18.5, 36.2),
('뉴건담', 'RX-93', 'Anaheim Electronics', 'Gundarium α Alloy', 18.5, 36.2),
('레전드 건담', 'ZGMF-X666S', 'Zodiac Alliance of Freedom Treaty', 'Variable Phase Shift armor', 18.66, 86.02),
('릭디아스', 'RMS-099', 'Anaheim Electronics', 'Gundarium γ Alloy', 18.0, 32.2),
('마라사이', 'RMS-108', 'Anaheim Electronics', 'Gundarium Alloy', 17.5, 33.1),
('베르데 버스터 건담', 'GAT-X103AP', 'Actaeon Industries', 'Variable Phase Shift Armor', 18.46, 99.36),
('블레이즈 자쿠 팬텀', 'ZGMF-1001/M', 'Integrated Design Bureau', null, 20.4, 91.2),
('스트라이크 건담', 'GAT-X105', 'Earth Alliance', 'Phase Shift Armor', 17.72, 64.8),
('건담 아스트레이 레드 프레임', 'MBF-P02', 'Morgenroete, Inc.', 'Foaming metal', 17.53, 49.8),
('알렉스', 'RX-78NT-1', 'Earth Federation', 'Luna Titanium', 18.0, 40.0),
('주다', 'EMS-10', 'Zimmad Company', 'Hardened Steel', 17.3, 61.0),
('캠퍼', 'MS-18E', 'Zeonic Company', 'Titanium Alloy Ceramic Composite', 17.7, 43.5),
('파워드 짐', 'RGM-79', 'Earth Federation', 'Titanium Ceramic Composite', 18.0, 46.6),
('프리덤 건담', 'ZGMF-X10A', 'Integrated Design Bureau', 'Phase Shift Armor', 18.03, 71.5);
select * from mechanic;
⭐Insert
insert into mechanic
values (NULL, '데스티니 건담', 'ZGMF-X42S',
'Zodiac Alliance of Freedom Treaty',
'Variable Phase Shift Armor',
18.08, 79.44);

insert into mechanic (name, model) values ('데스티니 건담', 'ZGMF-X42S');

따옴표 및 쌍따옴표
- 문자열 내에 따옴표(')가 포함된 경우에는 쌍따옴표(" ")로 감싸야 함
- 문자열 내에 쌍따옴표(")가 포함된 경우에는 따옴표(' ')로 감싸야 함
insert into mechanic (name, model) values ('"데스티니" 건담', 'ZGMF-X42S');
