-
07/13 데이터베이스 기초1데이터베이스 2021. 7. 13. 16:06
mysql 설치
mysql workbench 설치
https://dev.mysql.com/downloads/workbench/
MySQL :: Download MySQL Workbench
Select Operating System: Select Operating System… Microsoft Windows Ubuntu Linux Red Hat Enterprise Linux / Oracle Linux Fedora macOS Source Code Select OS Version: All Windows (x86, 64-bit) Recommended Download: Other Downloads: Windows (x86, 64-bit), M
dev.mysql.com
스키마 만들기
exam11
테이블 생성
멤버 테이블
members
제품 테이블
products
구매 테이블
purchases
mysql v5.6.5이상만 CURRENT_TIMESTAMP를 사용할 수 있다
외래키 등록
관계형성
컬럼의 인코딩 설정을 같게 해야지 외래키 등록가능
다이어그램 만들기
다이어그램 만들기 CRUD
삽입, 검색, 갱신, 삭제
#Create
INSERT INTO members values ('hong@gmail.com', '123456');#Read
SELECT * FROM members;#Update
UPDATE members SET email = 'lim@gmail.com' where email = 'hong@gmail.com';#Delete
DELETE FROM members WHERE email = 'lim@gmail.com';UUID생성
#UUID 생성
SELECT UUID() AS UUID_Value;DB사용선언
use [DB이름]
use exam11;
프로시저
프로시저 선언
delimiter // create procedure test() begin select uuid(); end// delimiter ;
프로시저 호출
call test();
호출 결과 프로시저 삭제
매개변수가 있는 프로시저
delimiter // create procedure insert_product(category int, name varchar(45), price int, amount int) begin declare uuid varchar(255); set uuid = uuid(); insert into products values(uuid, category, name, price, amount); end// delimiter ;
call insert_product(100, '게토레이', 1500, 5);
'데이터베이스' 카테고리의 다른 글
07/14 데이터베이스 기초 2 (0) 2021.07.14 06/16 Sequelize + node.js express 사용연습 2 (0) 2021.06.16 06/16 Sequelize + node.js express 사용연습 (0) 2021.06.16 06/15 node.js서버 express CRUD 구현 (0) 2021.06.15 06/15 DB update, delete 및 node.js서버 DB검색 구현 (0) 2021.06.15