이전 포스팅에서는 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 |