4주차 커리큘럼
MySQL에서 SQL쿼리 직접 작성(SQL-QUERY/ANSI-SQL)
테이블을 합쳐서 조회(JOIN)
에러핸들링(Try-Catch-Finally/Throw)
암호화 방식(Encrypt/Hash)
JWT(json web token)사용
mysql에는 1:n은 불가능하나 n:1은 가능하다.
show databases; //db보기
use myproject02; //해당
show tables; //어떤 테이블이 있는 지 확인
desc product; //product에 대한 설명
select * from product; // product테이블에 있는 모든 열을 가져오기
select price, name from product; //product테이블에 있는 price, name을 가져옴
insert into product (id, name, description, price, isSoldout) values(uuid(), '마우스', '정말 좋은 마우스입니다!!', 15000, false); //insert하는 방법
select * from product_saleslocation;
insert into product_saleslocation(id, address, addressDetail, lat, lng, meetingTime) values(uuid(), '구로구', '구로디지털단지역', 0.0, 0.1, '2022-12-31');
update product set name = '키보드'; //업데이트(위험한 쿼리 실행문 why? 다른 데이터들도 건들 수 있어서 조건이 필요함!)
update product set name = '키보드' where price = 15000; //가격이 15000원인 상품들을 골라내서 이름을 키보드로 변경.
insert into product (id, name, description, price, isSoldout) values(uuid(), '노트북', '최신 맥북!!', 20000, false)
select price, isSoldout from product where name = '노트북'//product에서 이름이 노트북인애만 조회해서 가격과 판매여부 가져오기
update product set productSaleslocationId = 'id~~' where name = '키보드';//name이 키보드인 애의 saleslocationid를 바꿈.
select * from product;
select * from product_saleslocation
select p.id, p.name, p.price, address, addressDetail from product p, product_saleslocation ps where p.productSaleslocationId = ps.id //alias설정을 통해 별칭으로 검색
quiz
카테고리 등록
insert into product_category(id, name) values(uuid(), '전자제품');
insert into product_category(id, name) values(uuid(), '음식');
insert into product_category(id, name) values(uuid(), '의류');
카테고리 등록 확인
select * from product_category;
새로운 상품 등록
insert into product (id, name, description, price, isSoldout) values(uuid(), '셔츠', '깨끗한 셔츠', 3000, false);
select * from product;
update product set productCategoryId = '의류카테고리id' where name = '셔츠';//이름이 셔츠인 아이템을 의류카테고리가 등록됨.
update product set productCategoryId = '전자제품id' where name = '노트북' or name = '키보드' ;//이름이 노트북, 키보드인 아이템을 전자제품카테고리에 등록
//둘을 합쳐서 확인할 때
select p.name as '상품명', pc.name as '카테고리명' from product p, product_category pc where p.productCategoryId = pc.id //alias설정을 통해 별칭으로 검색
key종류
PRI - primary key
UNI - unique key
MUL - foreign key
쿼리 안에서 쿼리 반복사용(where(sub query), from(inline view)등 다양한 곳에서도 sub query사용 가능, select(scalar subQuery)라 부름.