데이터 베이스 설계 실습
[최종 산출물]
<실습 목표>
기존에 존재하는 데이터 명세서를 기준으로 vs code 에 ERD 를 그려보자
//학과 테이블
Table departments {
id int [pk,increment,note: "학과 번호"]
dname varchar(100) [not null, note:"학과명"]
loc varchar(100) [not null, note:"위치"]
phone varchar(15) [not null, note:"전화번호"]
email varchar(100) [not null, note:"이메일 주소"]
established int [not null, note:"설립 연도"]
homepage varchar(255) [not null, note:"홈페이지 주소"]
}
// 교수 테이블
Enum professor_position {
A [note: "교수"]
B [note: "부교수"]
C [note: "조교수"]
D [note: "전임강사"]
}
Enum professor_status {
A [note: "재직"]
B [note: "휴직"]
C [note: "퇴직"]
}
Table professors {
id int [pk,increment,note: "교수 번호"]
name varchar(50) [not null, note:"이름"]
user_id varchar(50) [not null, note:"아이디"]
position professor_position [not null, note:"직급 (A=교수,B=부교수,C=조교수,D=전임강사)"]
sal int [not null, note:"급여"]
hiredate date [not null, note:"입사일"]
comm int [note:"보직수당"]
email varchar(100) [note:"이메일 주소"]
phone varchar(15) [note:"전화번호"]
photo_url varchar(255) [note:"프로필 사진 URL"]
status professor_status [not null, note:"재직상태 (A=재직,B=휴직,C=퇴직)"]
department_id int [not null,note:"소속 학과번호", ref: > departments.id]
}
//학생 테이블
Enum gender {
A [note: "남"]
B [note: "여"]
}
Enum student_status {
A [note: "재학"]
B [note: "휴학"]
C [note: "졸업"]
D [note: "퇴학"]
}
Table students {
studno int [pk,increment, not null, note: "학생 번호"]
name varchar(50) [not null, note:"이름"]
user_id varchar(50) [not null, note:"아이디"]
grade int [not null, note:"학년"]
idnum char(64) [not null, note:"주민등록번호(SHA2해시)"]
birthdate date [not null, note:"생년월일"]
phone varchar(13) [note:"전화번호"]
height int [not null, note:"키"]
weight int [not null, note:"몸무게"]
email varchar(100) [note:"이메일 주소"]
gender gender [note:"성별 (A=남,B=여)"]
status student_status [note:"직급 (A=재학,B=휴학,C=졸업,D=퇴학)"]
photo_url varchar(255) [ note:"프로필 사진 경로"]
admission_date date [note:"입학일"]
graduation_date date [note:"졸업일"]
department_id int [not null, note:"소속 학과번호",ref: > departments.id]
professor_id int [note:"지도 교수 번호",ref: > professors.id]
}
//과목 테이블
Table subjects {
id int [not null,pk,increment,note:"과목번호"]
name varchar(100) [not null,note:"과목명"]
credit int [not null,note:"학점"]
department_id int [not null,note:"개설 학과" ,ref: > departments.id]
professor_id int [note:"담당 교수",ref: > professors.id]
}
//수강 테이블
Table enrollments{
student_id int [not null,pk,note:"학생번호"]
subject_id int [not null,pk,note:"과목번호"]
enroll_date date [not null,note:"수강신청일"]
score int [note:"성적 점수 (100점 만점)"]
}
<겪었던 시행착오>
1.(순서) Enum 으로 열거형 데이터 사용시에는 TABLE 보다 상단에 써줘야함
2.Enum 정의 중복 주의
status 가 2개 있었는데 이름 정의를 다르게 해줘야함
이후 테이블 생성시에는 status 라고 동일한 이름으로 정의해도 무방
3. (오탈자 주의)
-FK REFERENCE 적을 떄
<추가 참고>
1. 생성한 DBML 을 SQL 문으로 변경하는 방법
Ctrl + Shift + P 를 누르면
상단에서 이런 메뉴가 활성화되는데, 그중 DBML : TO SQL 을 눌러주면
좌측에 새로운 SQL 파일이 생성되고 DBML 구문들이 SQL 구문 형식으로 바뀌어져 있음
2. 참고
'빅데이터 국비 교육' 카테고리의 다른 글
[아이티윌 빅데이터 52기] Day 7 Python Basic (0) | 2025.10.15 |
---|---|
[아이티윌 빅데이터 52기] Day 6 데이터 베이스 설계 (0) | 2025.10.14 |
[아이티윌 빅데이터 52기] Day 5 고급 데이터 조회 2 / 데이터 베이스 구축 (0) | 2025.10.13 |
[아이티윌 빅데이터 52기] Day 4 데이터 입력/수정/삭제/데이터 고급 조회 1 (0) | 2025.10.10 |
[아이티윌 빅데이터 52기] Day 3 SQL 함수 2 그룹 조회 (0) | 2025.10.02 |