임시 테이블 (Temporary Tables)
-- 세션 동안만 유지되는 임시 테이블 생성 (SQL Server 예제)
CREATE TEMPORARY TABLE #temp_top_customers (
customer_id INT,
total_spent DECIMAL(10,2)
);
-- 임시 테이블에 데이터 삽입
INSERT INTO #temp_top_customers
SELECT customer_id, SUM(amount)
FROM orders
GROUP BY customer_id
HAVING SUM(amount) > 10000;
-- 임시 테이블 조회
SELECT * FROM #temp_top_customers ORDER BY total_spent DESC;
blur_on 설명
- 세션이나 트랜잭션 동안만 존재하는 임시 테이블
- 중간 결과 저장이나 복잡한 쿼리 분해 시 유용
- 데이터베이스 종류에 따라 생성 문법이 다름(#, TEMPORARY, GLOBAL TEMPORARY 등)