Sql
-
mysql 프로시저 활용하기Sql 2023. 9. 7. 08:16
데이터를 (),(),(); 형태로 만들었고, insert하기 위한 프로시저를 실행시켰다 프로시저를 활용하는 이유 : insert / update 는 실행 중 일때 데이터의 안정성을 위해 해당 작업이 끝날 때 까지 다른 작업을 시작하지 않는다. 그렇기 때문에 실제로 운영하는 서버에서는 insert,update를 수행하는 시간을 매우짧게 가져가야한다. 여기서는 배열 형태의 데이터를 임시테이블에 저장해뒀다가 insert 시키기 위해 프로시저를 활용했다. CREATE DEFINER=`host` PROCEDURE `DataInsert`( IN `input_string` TEXT, IN `standardDate` INT ) LANGUAGE SQL NOT DETERMINISTIC CONTAINS SQL SQL SEC..
-
중복확인 쿼리문Sql 2023. 9. 4. 14:34
데이터베이스에 데이터를 넣은 후, 중복된 값이 존재하는지 확인하는 쿼리문이 있다 SELECT * FROM price GROUP BY ID, DATE HAVING COUNT(1) > 1 ORDER BY 1 DESC LIMIT 100; -> ID를 기준으로 100 번째 까지, id 와 date열을 그룹으로 묶어서 count(1) > 1 즉 하나 이상의 행이 있는 요소들을 select 하는 것이다. 따라서 해당 쿼리문의 결과로 아무런 데이터가 나오지 않는다면, 중복되는 값이 하나도 없다는 뜻이다
-
mySQL 버전에 따른 쿼리문Sql 2023. 6. 25. 20:24
학원에서 사용하던 쿼리문을 집에서 사용하니 ### Error querying database. Cause: java.sql.SQLSyntaxErrorException: Expression 2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'control_third_project.o.order_date' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 다음의 에러가 발생했다. 같은 mysql이더라도, 버전이 다르면 쿼리문의 이용 방법이 조금 변하는 것 같..
-
mySQL 다운받기Sql 2023. 5. 7. 00:29
mySql을 다운받아서 실행하려면, https://dev.mysql.com/downloads/workbench/ MySQL :: Download MySQL Workbench Select Operating System: Select Operating System… Microsoft Windows Ubuntu Linux Red Hat Enterprise Linux / Oracle Linux Fedora macOS Source Code Select OS Version: All Windows (x86, 64-bit) Recommended Download: Other Downloads: Windows (x86, 64-bit), M dev.mysql.com 여기서 워크밴치를 다운 받고, https://dev.mys..
-
mySql Connections 설정 ( IP 주소 이용 )Sql 2023. 4. 17. 11:55
기존에 사용하던 mySql의 커넥터는 localhost에만 한정되어 있었기 때문에, 다른 컴퓨터에서는 데이터베이스에 접근할 수가 없었다. Connections를 ip 주소로 생성하면, 다른 컴퓨터에서도 해당 데이터베이스에 접근할 수 있다. 1. IP 주소 찾기 - cmd 에서 ipconfig를 실행하면 해당 컴퓨터의 ip 주소를 알 수 있다. 이번에는 같은 강의실에 있는 컴퓨터들이 접근할 수 있도록 IPv4 주소를 이용할 것이다. 2. 데이터베이스 생성 및 user 생성 - 공유해서 사용하고 싶은 데이터베이스를 생성해준다 - navigator 아래의 administration 탭을 클릭하면 다음과 같은 창이 뜬다 - user and privileges 탭을 클릭하면 계정을 관리하는 창이 나온다. - ad..
-
제약조건 확인, 제약조건 제거Sql 2023. 3. 24. 09:43
테이블에 걸린 제약조건을 확인할 수 있다. 모든 테이블에 걸린 제약조건 확인 select * from information_schema.table_constraints; 특정 테이블에 걸린 제약조건 확인 select * from information_schema.table_constraints where table_name = '테이블명'; - 제약조건에 이름을 지정하지 않고 만들었더라도 자동으로 부여된 이름을 찾을 수 있다. 제약조건 제거 alter table 테이블명 drop 제약조건 제약조건명;
-
My Sql 첫걸음 CH08. 트랜잭션Sql 2023. 3. 17. 15:05
1 _ 트랜잭션 : insert나 update 명령으로 데이터를 추가, 갱신할 때도 트랜잭션 기능을 사용하지만, 자동 커밋 기능이 동작했기 때문에 눈치 체지 못 했을 것이다. 트랜잭션의 제어 START TRANSACTION COMMIT ROLLBACK -> insert나 update 기능을 사용할 때 해당 기능들이 모두 성공하면 commit 기능들 중에 하나라도 실패했다면 rollback한다. - transaction 없이 update하면 count에 +1이 되며 자동으로 commit 된다 하지만 transaction을 시작한 후 update 나 insert 명령을 정상적으로 수행했다면, commit; 명령으로 commit 시켜줘야한다. 만일 update 나 insert 명령이 정상적이지 않았다면, tr..
-
My Sql 첫걸음 CH08. 데이터베이스 설계Sql 2023. 3. 17. 15:02
1 _ 데이터베이스 설계 : 데이터베이스의 스키마 내에 테이블, 인덱스, 뷰 등의 데이터베이스 객체를 정의하는 것을 말한다. 스키마 내에 정의한다는 뜻에서 '스키마 설계'라 불리기도 한다. 데이터 베이스에서 사용될 이름으로 논리명과 물리명이 있다. 논리명 : 테이블의 설계상 이름 물리명 : create table 처럼 지정하는 이름을 말한다. 2 _ er 다이어그램 : 테이블 간의 관계를 명확히 하기 위해서 설계도를 작성한다. erd 관계선 종류 실선 : 부모 테이블 pk 가 자식 테이블 fk가 되는 경우 점선 : 부모 테이블 pk 가 자식 테이블의 일반속성이 되는 경우 erd 기호의 종류 | : 1개 < : 여러개 o : 0개 선 끝에 3지창으로 되어있는 곳은 선이 나오는 지점에서 3지창 방향의 테이블..