DBML

임재현·2024년 3월 28일
0
post-thumbnail

DBMS

RDBMS

RDBMS : Relational Database Management System 관계형DB
-> PK, FK(Foreign Key)

schema

데이터베이스의 전체적인 구조

1. 개체들의 속성 (Attribute)
2. 속성들로 이루어진 개체 (Entity)
3. 개체사이의 관계 (Relation)

table

행과 열로 이루어진 데이터 모음

1. 데이터를 구조적으로 묶은 목록

SQL

SQL : Structured Query Language

HandsOn 1

고객이 주문을 한다.

-> entity : 고객, 주문
table customer_t
{
  idx bigint [pk, increment]
  email varchar [not null]
  addr varchar(255)
}

table orders_t
{
  idx bigint [pk, increment]
  order_date date [not null]
  customer_t_idx bigint [ref: > customer_t.idx]
}

customer

idx(PK)emailaddr
1kavin@gamil.combusan
2david@gamil.comseoul

order

idx(PK)order_datecustomer_t_idx(FK)
12024-03-282
22024-03-281
32024-03-281
고객이 상품을 주문한다.

HandsOn 2

카페에 주문하기 위해서는 회원가입 필요
회원가입 시 이름과 이메일 정보 필요
카페는 반드시 카페소유주와 카페의 닉네임이 필요

Step1. cafe에 회원가입을 한다
Table cafe
{
  cafe_idx bigint [pk, increment]
  name varchar(20) [not null]
  ownner varchar(10) [not null]
  nickname varchar(10) [not null, unique]
  customer_idx bigint [ref: > customer.customer_idx]
}

Table customer
{
  customer_idx bigint [pk, increment]
  email varchar(20) [not null, unique]
  cafe_idx bigint [ref: > cafe.cafe_idx]
}

cafe->customer(1:N)
cafe

cafe_idxnameownernickname
1starkavinkavin
2ediajasongoogi

customer

idxemailcafe_idx
1david@gamil.com1
2david@gamil.com2

customer->cafe
cafe

cafe_idxnameownernicknamecustomer_idx
1starkavinkavin1
2ediajasongoogi1
3starkavinkavin2

customer

idxemail
1david@gamil.com
2json@gamil.com

-> N:N의 관계는 설계를 할 때 주의
하나의 테이블을 도출해서 1:N의 관계로 재설계하는 방안으로 지향

Step2. 주문을 한다

Step3. 아메리카노를 주문한다

Stem4. 고객은 장바구니에 상품을 주문한다

Table customer{
  customer_idx bigint [pk, increment]
  email varchar(20) [not null, unique]
  name varchar(10) [not null]
}
Table orders{
  order_idx bigint [pk, increment]
  order_date date [not null]
  cart_idx bigint [ref: - cart.cart_idx]
}

Table product{
  product_idx bigint [pk, increment]
  product_name varchar(10) [not null]
  product_price int [not null]
  market_idx bigint [ref : > market.market_idx]
}

Table cart
{
  cart_idx bigint [pk, increment]
  cart_date date [not null]
  customer_idx bigint [ref: > customer.customer_idx]
}

Table product_cart_bridge
{
  product_cart_bridge bigint [pk, increment]
  product_idx bigint [ref: >product.product_idx]
  cart_idx bigint [ref:>cart.cart_idx]
}

Table market
{
  market_idx bigint [pk, increment]
  market_name varchar(10) [not null]

}
Step5. 예제

table Customer {
  CustomerID bigint [pk, increment]
  CustomerName varchar(50) [not null]
  ContactName varchar(50) [not null]
  Address varchar(150) [not null]
  City varchar(20) [not null]
  PostalCode varchar(10) [not null]
  Country varchar(20) [not null]
}

table Shipper {
  ShipperID bigint [pk, increment]
  ShipperName varchar(20) [not null]
  Phone varchar(20) [not null]
}

table Category{
  CategoryID bigint [pk, increment]
  CategoryName varchar(20) [not null]
  Description text [not null]//text는 고정 사이즈
}

table Employee {
  EmployeeID bigint [pk, increment]
  LastName varchar(30) [not null]
  FirstName varchar(30) [not null]
  BirthDate date [not null]
  Photo varchar(30) [not null]
  Notes text [not null]
}

table Supplier {
  SupplierID bigint [pk, increment]
  SupplierName varchar(20) [not null]
  ContactName varchar(20) [not null]
  Address varchar(50) [not null]
  City varchar(20) [not null]
  PostalCode varchar(20) [not null]
  Country varchar(20) [not null]
  Phone varchar(20) [not null]
}

table Orders {
  OrderID bigint [pk, increment]
  OrderDate date [not null]
  CustomerID bigint [not null]
  EmployeeID bigint
  ShipperID bigint [not null]
}

table OrderDetail {
  OrderDetailID bigint [pk, increment]
  Quantity int [not null]
  OrderID bigint [not null]
  ProductID bigint [not null]
}

table Product {
  ProductID bigint [pk, increment]
  ProductName varchar(20) [not null]
  Unit varchar(20) [not null]
  Price bigint [not null]
  SupplierID bigint [not null]
  CategoryID bigint [not null]
}

ref: Orders.CustomerID > Customer.CustomerID [delete: cascade, update: no action]
//delete: cascade customerID 삭제되면 주문서도 같이 삭제
//update : no action 해당 값이 변경될시 order도 동일하게 업데이트
ref: Orders.EmployeeID > Employee.EmployeeID
ref: Orders.ShipperID > Shipper.ShipperID
ref: OrderDetail.OrderID > Orders.OrderID [delete: cascade, update: no action]
ref: OrderDetail.ProductID > Product.ProductID
ref: Product.SupplierID > Supplier.SupplierID
ref: Product.CategoryID > Category.CategoryID

Netflips

1. 회원가입
	a. 이메일, 비번
    b. 멤버쉽
    c. 닉네임
2. 회원가입 후 개인화 항목들
3. 메인페이지
	a. 테마별 영화리스트
    	i. 영화상세
        ii. 시리즈
        iii. 영화
        
        
        

j

table user_info
{
  user_id bigint [pk, increment]
  user_pw varchar(50) [not null]
  user_email varchar(50) [not null, unique]
  user_sign_up_date date [not null]
  membership_id bigint [not null]
}

table profile
{
  profile_id bigint [pk, increment]
  profile_language varchar(50) [not null]
  user_id bigint
  profile_name varchar(50) [not null]
  film_rating_id bigint//관람등급
}

table membership//멤버쉽 가입된 유저 1:1 매칭
{
  membership_id bigint [pk, increment]
  membership_name varchar(50) [not null]
  membership_sign_up_date date [not null]
}

table watching_history // 시청 기록
{
  watching_history_history_id bigint [pk, increment]
  profile_id bigint [not null]
  content_id bigint [not null]
}

table content
{
  content_id bigint [pk, increment]
  content_name varchar(50) [not null]
  content_description varchar(255) [not null]//영화, 시리즈 메인 요약
  content_sub_description varchar(255)//시리즈 회차 요약
  content_uri varchar(255) [not null]
  content_thumbnail varchar(255) [not null]//영화, 시리즈 메인 썸네일
  content_sub_thumbnail varchar(255)//시리즈 서브 썸네일
  content_view bigint [not null]
  type_id bigint [not null]
  director_id bigint [not null]
  film_rating_id bigint [not null]
}

table content_category_bridge
{
  content_category_bridge_id bigint [pk, increment]
  category_id bigint [not null]
  content_id bigint [not null]
}

table category // 장르
{
  category_id bigint [pk, increment]
  category_name varchar(50) [not null]
}

table type // 영화 or 드라마
{
  type_id bigint [pk, increment]
  type_name varchar(50) [not null]
}

table director
{
  director_id bigint [pk, increment]
  director_name varchar(50) [not null]
}

table film_rating
{
  film_rating_id bigint [pk, increment]
  film_rating_name varchar(50) [not null]
}

table actor
{
  actor_id bigint [pk, increment]
  actor_name varchar(50) [not null]
  actor_photo varchar(255)
}

table content_actor_bridge
{
  content_actor_bridge_id bigint [pk, increment]
  actor_id bigint [not null]
  content_id bigint [not null]
}

ref: profile.profile_id < watching_history.profile_id
ref: content.content_id < watching_history.content_id
ref: profile.user_id > user_info.user_id
ref: content.type_id > type.type_id
ref: content.director_id > director.director_id
ref: content.film_rating_id > film_rating.film_rating_id
ref: content_category_bridge.category_id > category.category_id
ref: content_category_bridge.content_id > content.content_id
ref: membership.membership_id < user_info.membership_id
ref: actor.actor_id < content_actor_bridge.actor_id
ref: content.content_id < content_actor_bridge.content_id

GPT에 더미데이터를 요청해서 INSERT

0개의 댓글