[Linux | DB] DB Server 쇼핑몰 데이터베이스 구축 - 2

2025. 1. 8. 16:44·OS/Linux

이전 포스팅에서는 DB 서버에 데이터베이스를 생성하고, 테이블을 정의를 해봤다. 그래서 이번시간은 생성했던 데이터베이스 안 각 테이블에 데이터를 삽입을 해볼 것이다. 해보자. 해보자!


데이터 테이블에 데이터 삽입

1. users - 고객 데이터 삽입

MariaDB [shopping_mall]> INSERT INTO users (username, email, password) VALUES
    -> ('Dongwoo', 'dongwoosin@example.com', 'password123'),
    -> ('Jane', 'jane@example.com', 'password456'),
    -> ('John', 'john@example.com', 'password1'),
    -> ('Conan', 'conan@example.com', 'password2');
Query OK, 4 rows affected (0.001 sec)
Records: 4  Duplicates: 0  Warnings: 0


2. categories - 카테고리 데이터 삽입

MariaDB [shopping_mall]> INSERT INTO categories (name) VALUES
    -> ('Electronics'),
    -> ('Books'),
    -> ('Clothing');
Query OK, 3 rows affected (0.001 sec)
Records: 3  Duplicates: 0  Warnings: 0


3. products - 상품 데이터 삽입 (본 데이터는 example일 뿐입니다.)

MariaDB [shopping_mall]> INSERT INTO products (name, description, price, stock, category_id) VALUES
    -> ('Mac-book pro mk-240', 'high performance laptop', 2500.00, 10, 1),
    -> ('SamSung-laploop Sa-270', '4k display with good performance laptop', 2000.00, 25, 1),
    -> ('LG-laptop LG-239', 'very low weight laptop', 2400.00, 15, 1),
    -> ('the one thing', 'focus on one thing', 15.00, 20, 2),
    -> ('the kinfolk table', 'about kinfolk table', 12.00, 25, 2),
    -> ('linux master book 2024', 'about linux', 14.00, 50, 2),
    -> ('nike-sweater', 'nike', 24.00, 100, 3),
    -> ('addidas-sweater', 'addidas', 26.00, 120, 3),
    -> ('polo-sweater', 'polo', 34.00, 48, 3);
Query OK, 9 rows affected (0.002 sec)
Records: 9  Duplicates: 0  Warnings: 0


4.  orders - 주문 데이터 삽입

MariaDB [shopping_mall]> INSERT INTO orders (user_id, total_amount) VALUES
    -> (1, 68.00),
    -> (2, 4800.00),
    -> (3, 2500.00),
    -> (4, 90.00);
Query OK, 4 rows affected (0.002 sec)
Records: 4  Duplicates: 0  Warnings: 0


5. order_deails - 주문 상세 데이터 삽입

MariaDB [shopping_mall]> INSERT INTO order_details (order_id, products_id, quantity, price) VALUES
    -> (1, 9, 2, 34.00),
    -> (2, 3, 2, 2400.00),
    -> (3, 1, 1, 2500.00),
    -> (4, 4, 6, 15.00);
Query OK, 4 rows affected (0.001 sec)
Records: 4  Duplicates: 0  Warnings: 0

 

이렇게 각 테이블에 데이터를 삽입 해줬다. 다음 작업으로 특정 고객의 주문 내용을 조회해볼 것이다. 


특정 고객 주문 내용 조회

MariaDB [shopping_mall]> SELECT o.order_id, o.order_date, od.products_id, od.quantity, od.price, o.total_amount
    -> FROM orders o
    -> JOIN order_details od ON o.order_id = od.order_id
    -> WHERE o.user_id = 1;

 

일단 오늘은 여기까지 하겠다. 

 

저작자표시 비영리 변경금지 (새창열림)

'OS > Linux' 카테고리의 다른 글

[Linux] 하드 디스크 mount 방법  (0) 2025.01.21
[Linux] 리눅스 복습 | Ubuntu22.04 / Rocky9 / CentOS8 재설치  (0) 2025.01.14
[Linux | DB] DB Server 쇼핑몰 데이터베이스 구축 - 1  (0) 2025.01.08
[Linux | Rocky 9] 리눅스 DNS 서버  (1) 2024.12.17
[Linux] DNS - Root Hint & DNS 서버 및 위임  (0) 2024.12.17
'OS/Linux' 카테고리의 다른 글
  • [Linux] 하드 디스크 mount 방법
  • [Linux] 리눅스 복습 | Ubuntu22.04 / Rocky9 / CentOS8 재설치
  • [Linux | DB] DB Server 쇼핑몰 데이터베이스 구축 - 1
  • [Linux | Rocky 9] 리눅스 DNS 서버
Kouji
Kouji
Journey to Becoming a Data & Server Engineer
  • Kouji
    Kouji's Data & Server Journey
    Kouji
  • 전체
    오늘
    어제
    • 분류 전체보기
      • Programming
        • Python
        • SQL
      • Data & AI
        • Data Analysis
        • Ai
      • Cloud(AWS)
      • OS
        • Linux
        • Docker
        • Jenkins
        • Ubuntu
        • Window
        • Kubernates
        • Ansible
      • Network
        • NVIDIA
        • Network[이론]
        • Network[GNS3, Packet]
        • Network[On-Premise]
        • Network [L2, L3]
      • 트러블 슈팅
      • Life
        • My Career Stories
        • Personal
      • 개발 + OS 지식 함양
  • 블로그 메뉴

    • 홈
    • 관리 페이지
    • 글쓰기
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    라우팅
    docker
    VMware
    오블완
    네트워크관리사
    화이팅
    웹
    클라우드엔지니어
    알고리즘
    L3
    서버엔지니어
    Linux
    보안
    인프라
    AWS
    네트워크
    티스토리챌린지
    인프라엔지니어
    리눅스
    네트워크엔지니어
    스위치
    dns
    OS
    CISCO
    ubuntu
    네트워크엔지니어링
    도커
    IT
    서버
    시스템엔지니어
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.3
Kouji
[Linux | DB] DB Server 쇼핑몰 데이터베이스 구축 - 2
상단으로

티스토리툴바