Update 7

[MySQL] trigger 생성 예제 : update after, old, new

trigger 생성 문제 attend테이블의 co_code를 update하면 course테이블의 at_co_code 와 attend테이블의 co_code가 연결되어 있으니, co_code에 맞는 old.co_degree는 -1 / new.co_degree는 +1 되는 트리거 생성 1. update를 두번 사용하는 방법 mysql> delimiter // mysql> create trigger update_attend after update on attend -> for each row -> begin -> update course set co_degree = co_degree -1 -> where co_code = old.at_co_code; -> update course set co_degree = c..

[MySQL] trigger 생성 예제 : after insert, new (함수사용X)

1. school 데이터 베이스 - course테이블의 해당 코스의 수강인원을 집계하는 필드 생성 co_degree필드 생성 mysql> alter table course add column co_degree int default 0; 2. co_degree 필드에 해당 코스를 듣는 인원수를 집계하여 업데이트 join을 사용하지 않아도 참고가 가능한 이유 update의 구문 = course 사용가능 select의 구문 = attend 사용가능 join을 이용하는 경우, 해당테이블을 두번 가져오는 것으로 오류 발생 update course c set co_degree = (select count(a.at_num) from attend where a.at_co_code = c.co_code ) ; -- 알리..

[MySQL] ERD 대학수강프로그램 - 4. 테이블 업데이트 (update, case, if, modify)

1. at_mid, at_final, at_attend, at_homework 값 업데이트 (40/40/10/10) update attend set at_homework = 8 where at_num=1; update attend set at_homework = 5 where at_num=2; update attend set at_homework = 2 where at_num=3; update attend set at_homework = 10 where at_num=4; update attend set at_homework = 7 where at_num=5; update attend set at_homework = 5 where at_num=6; update attend set at_homework = ..

[MySQL] ERD 수강관리프로그램 3.업데이트 (update, if, case)

1. attend 테이블의 수강년도(at_year) 을 2023으로 변경 mysql> update attend set at_year = 2023; Query OK, 16 rows affected (0.00 sec) Rows matched: 16 Changed: 16 Warnings: 0 mysql> select * from attend; +--------+------------+-------------+---------+---------+--------+----------+-----------+-------+---------------+----------+ | at_num | at_std_num | at_co_code | at_year | at_term | at_mid | at_final | at_att..

[MySQL] 테이블 데이터 변경, 삭제, 중복제거 Update, delete, distinct

테이블 튜플(안의 데이터) 변경 : Update -- 데이터 변경 Update 테이블명 set 바꿀칼럼 = '값' where 조건 ; -- 타 테이블에서 값을 가져와 데이터 변경 update 테이블명 set 칼럼명 = (select 타테이블칼럼명 from 타테이블명 where 조건 ) ; /* 강감찬의 major1을 'computer'로 변경 */ mysql> update student set major1='computer' where num=4444; mysql> select * from student; +------+--------+------+---------+----------+-------+ | num | name | age | address | major1 | score | +------+--..

[MySQL] student table - 22=1학년, 23=2학년, 24=3학년, 25=4학년으로 하는 grade속성 추가

mysql> update student set grade = 1 where age = 22; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 ysql> update student set grade = 3 where age = 24; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update student set grade = 2 where age = 23; Query OK, 2 rows affected (0.00 sec) Rows matched: 2 Changed: 2 Warnings: 0 mysql> update st..