'Programming/SQL'에 해당되는 글 3건

TRANSACTION이란?

여러 개의 SQL문을 하나의 처리로 규정하는 기능
중간에 오류가 나면 모든 작업을 원상태로 되돌린다.

TRANSACTION 테스트 케이스 진행과정

  1. CRUD 테스트 케이스에서 시작
  2. TRANSACTION : ROLLBACK 테스트
    • 돌고래, 기린 추가 후 취소(ROLLBACK) 시험
    • id는 Auto Increment : 자동 생성되며 늘어나니 따로 추가할 필요 없음
    • start transaction;
      insert into math_score(name, score) values("돌고래", 10); 
      insert into math_score(name, score) values("기린", 360);
      rollback;
  3. ROLLBACK 결과확인
  4. TRANSACTION : COMMIT 테스트
    • 돌고래, 기린 추가 후 Commit 시험
    • id는 Auto Increment : 자동 생성되며 늘어나니 따로 추가할 필요 없음
    • start transaction;
      insert into math_score(name, score) values("돌고래", 10); 
      insert into math_score(name, score) values("기린", 360);
      commit;
  5. COMMIT 결과 확인
    • id는 테스트를 위해서 몇 번 하다보니 바뀜, id의 숫자는 무시 

'Programming > SQL' 카테고리의 다른 글

[SQL] JOIN 테스트 케이스  (0) 2021.02.18
[SQL] CRUD 테스트 케이스  (0) 2021.02.18
블로그 이미지

RIsN

,

JOIN이란?

서로 다른 테이블의 데이터를 같이 조작할때 사용

JOIN 테스트 케이스 진행과정

  1. CRUD 테스트 케이스에서 시작
  2. 테이블(Table : 데이터베이스 테이블) 설계(math_comment) 후 생성
    1. UTF-8 설정
    2. id / INT : pk(Priority Key : 고유 키), nn(Not Null : Null 불가), ai(Auto Increment : 알아서 숫자가 늘어나며 생성)
    3. student_id / INT : nn
    4. comment / VARCHAR(255) : nn
  3. 학생ID(student_id)를 외래 키(Foreign Keys) 설정
    • 데이터베이스 test_schema의 math_score를 참조
    • student_id와 math_score의 id를 연결  
  4. 스키마 내 테이블 스테이터스 확인
    • show tables;
  5. 테이블 math_score 와 math_comment 스테이터스 확인
    • desc math_score;
      desc math_comment;
  6. Create 테스트 케이스 작성
    • 이지은(student_id : 1), 성소(student_id : 2), 전효성(student_id : 3)의 수학 코멘트(math_comment) 추가
    • id는 Auto Increment : 자동 생성되며 늘어나니 따로 추가할 필요 없음
    • insert into math_comment(student_id, comment) values(1, '꽃갈피');
      insert into math_comment(student_id, comment) values(1, '팔레트');
      insert into math_comment(student_id, comment) values(2, '이루리');
      insert into math_comment(student_id, comment) values(3, '반해');
  7. INNER JOIN 테스트
    • 1번째 라인은 무엇(CRUD)을 할 지에 대해서와 기준 테이블과 JOIN 테이블을 정함
      2번째 라인에서 어떤 동일한 데이터를 확인할 지를 정함
      <추가 Where> 3번째 라인에서 어떤 것을 기준으로 찾을지를 정함  
    • 3번째 줄 : 우선 '이지은'이라는 학생 데이터
      2번째 줄 : math_comment의 학생 아이디(student_id)와 math_score의 학생 아이디(id)가 같은 데이터
      1번째 줄 : 기준은 math_comment이고, math_score를 합치되 math_comment의 데이터만 표시
    • select math_comment.* from math_comment inner join math_score 
      on math_score.id = math_comment.student_id
      where math_score.name = "이지은";
  8. INNER JOIN 테스트케이스 최종 확인
    • id는 테스트를 위해서 몇 번 하다보니 바뀜, id의 숫자는 무시 

>> 다음 TRANSACTION 테스트로

'Programming > SQL' 카테고리의 다른 글

[SQL] TRANSACTION 테스트 케이스  (0) 2021.02.18
[SQL] CRUD 테스트 케이스  (0) 2021.02.18
블로그 이미지

RIsN

,

CRUD란?

Create : 생성
Read : 읽기
Update : 갱신
Delete : 삭제

CRUD 테스트 케이스 진행과정

  1. MySQL Workbench 구성
  2. 스키마(Schema : 데이터베이스) 설계(test_schema) 후 생성
    1. UTF-8 설정
  3. 테이블(Table : 데이터베이스 테이블) 설계(math_score) 후 생성
    1. UTF-8 설정
    2. id / INT : pk(Priority Key : 고유 키), nn(Not Null : Null 불가), ai(Auto Increment : 알아서 숫자가 늘어나며 생성)
    3. name / VARCHAR(45) : nn
    4. score / INT : nn
  4. 사용할 스키마 설정
    • use test_schema;
  5. 스키마 내 테이블 스테이터스 확인
    • show tables;
  6. 테이블 math_score 스테이터스 확인
    • desc math_score;
  7. Create 테스트
    • 아이유, 성소, 전효성, 딜리트 등 점수 추가
    • id는 Auto Increment : 자동 생성되며 늘어나니 따로 추가할 필요 없음
    • insert into math_score(name, score) values("아이유", 120);
      insert into math_score(name, score) values("성소", 9999);
      insert into math_score(name, score) values("전효성", 158);
      insert into math_score(name, score) values("딜리트", 0);
  8. Read 테스트
    • 우선 테이블의 전체 내용 확인 
    • select * from math_score;
    • 이름(name)이 아이유인 데이터만 확인 
    • select * from math_score where name = "아이유";
    • 점수(score)가 150점 초과인 데이터들의 이름(name)만 확인
    • select name from math_score where score > 150;
    • 테이블의 전체 내용을 가져오되 점수(score)를 내림차순으로 확인
    • select * from math_score order by score desc;
  9. Update 테스트
    • 이름이 아이유인 데이터의 이름을 이지은으로 변경 
    • update math_score set name = '이지은' where name = '아이유';
  10. Delete 테스트
    • 이름이 딜리트인 것을 제거
    • delete from math_score where name = '딜리트';
    • 참고(테스트 중 실행 안함) : 테이블 내 모든 것 제거
    • delete from math_score;
  11. 테스트케이스 최종 확인
    • id의 숫자는 테스트 시 변경될 수 있으므로 무시 
  12. 전체 코드
    • use test_schema;
      
      -- Check
      show tables;
      desc math_score;
      
      -- Create
      insert into math_score(name, score) values("아이유", 120);
      insert into math_score(name, score) values("성소", 9999);
      insert into math_score(name, score) values("전효성", 158);
      insert into math_score(name, score) values("딜리트", 0);
      
      -- Read
      select * from math_score;
      select * from math_score where name = "아이유";
      select name from math_score where score > 150;
      select * from math_score order by score desc;
      
      -- Update
      update math_score set name = '이지은' where name = '아이유';
      
      -- Delete
      delete from math_score where name = '딜리트';

>> 다음 JOIN 테스트로

'Programming > SQL' 카테고리의 다른 글

[SQL] TRANSACTION 테스트 케이스  (0) 2021.02.18
[SQL] JOIN 테스트 케이스  (0) 2021.02.18
블로그 이미지

RIsN

,