1. The document discusses various SQL constraints that can be used when creating tables such as PRIMARY KEY, NOT NULL, DEFAULT, UNIQUE, and AUTO_INCREMENT.
2. Examples are provided of creating tables with different constraints like PRIMARY KEY to enforce a unique identifier column, NOT NULL for required fields, DEFAULT to set a default value, and UNIQUE for uniquely identifying columns.
3. The document also covers composite UNIQUE constraints to enforce uniqueness across multiple columns together rather than individually.
This document provides an introduction to cron and crontab in Linux. It explains that cron allows users to schedule commands to run periodically or at certain times. The document covers checking if cron is running, examples of cron usage, and the basic crontab syntax for scheduling jobs. It is written in Korean for beginner Linux users.
1. The document discusses various SQL constraints that can be used when creating tables such as PRIMARY KEY, NOT NULL, DEFAULT, UNIQUE, and AUTO_INCREMENT.
2. Examples are provided of creating tables with different constraints like PRIMARY KEY to enforce a unique identifier column, NOT NULL for required fields, DEFAULT to set a default value, and UNIQUE for uniquely identifying columns.
3. The document also covers composite UNIQUE constraints to enforce uniqueness across multiple columns together rather than individually.
This document provides an introduction to cron and crontab in Linux. It explains that cron allows users to schedule commands to run periodically or at certain times. The document covers checking if cron is running, examples of cron usage, and the basic crontab syntax for scheduling jobs. It is written in Korean for beginner Linux users.
6. 서브 쿼리 예제 1
‘맥북’을 팔고 있는 유저의 정보를 출력하세요.
바깥쪽 쿼리 : OUTER QUERY
안쪽 쿼리 : INNER QUERY, SUB QUERY
SELECT * FROM user u
WHERE u.id =
( SELECT seller FROM trade t
WHERE item_name = '맥북'
);
7. 서브 쿼리의 특징
SELECT, INSERT, UPDATE, DELETE 모두에 사용 가능
단, 안쪽 쿼리는 무조건 SELECT 쿼리입니다.
8. 서브 쿼리의 특징
모든 단일 값(스칼라)이 올 수 있는 자리에 사용 가능
하나의 레코드가 올 수 있는 자리도 대치 가능
테이블(여러 레코드)이 올 수 있는 자리도 대치 가능
9. 스칼라 값 대체 쿼리
GTA5를 팔고 있는 유저 1명의 정보를 출력하세요.
SELECT * FROM user u
WHERE u.id =
( SELECT seller FROM trade t
WHERE item_name = ‘GTA5‘ limit1
);
10. 스칼라 값 대체 쿼리
2번 마켓에서 가장 많은 상품을 팔고 있는 사람의 정보를
출력하세요.
11. 스칼라 값 대체할 때 주의사항
서브 쿼리의 결과값으로 두 개의 값이 오면 에러 발생
12. IN 과 NOT IN
IN과 NOT IN은 스칼라 집합에 대해 사용 가능
예)
아이폰을 팔고 있는 유저의 정보를 모두 출력하시오
SELECT * FROM user
WHERE iD = (
SELECT seller FROM trade
WHERE item_name like '아이폰%'
);
13. IN 과 NOT IN
IN과 NOT IN은 스칼라 집합에 대해 사용 가능
예)
아이폰을 팔고 있는 유저의 정보를 모두 출력하시오
SELECT * FROM user
WHERE id IN (
SELECT seller FROM trade
WHERE item_name like '아이폰%'
);
24. FROM 절의 서브쿼리
FROM 절에도 쿼리가 올 수 있습니다.
반드시 테이블에 별명을 붙여줘야 합니다.
SELECT m.name, m.item_name
FROM
(SELECT *
FROM user u LEFT JOIN
TRADE t ON u.id = t.seller) AS m;
25. VIEW
SELECT 쿼리를 이용해서 만든 가상 테이블
용량을 차지하지 않음
생성: CREATE VIEW 명령 사용
CREATE VIEW 뷰이름 as (SELECT…);
사용 : 일반적인 테이블과 동일
SELECT * FROM 뷰이름 ...;
삭제 : DROP VIEW 명령 사용
DROP VIEW my_view;
26. 학습 정리
서브 쿼리에 대해 배웠습니다.
서브 쿼리를 사용하면 의미가 명확해 집니다.
중첩 상관 쿼리는 성능이 좋지 않을 수 있습니다.
데이터베이스에 따라 최적화에 의해 성능이 달라집니다.