본문 바로가기

Mysql

(8)
Mysql 08 Transaction create table tbl_test ( no int primary key, name varchar(20), age int, gender char(1) ); insert into tbl_test values(1,'aa',66,'W'); -- commit; insert into tbl_test values(2,'aa',66,'W'); -- commit; insert into tbl_test values(3,'aa',66,'W'); -- commit; commit; start transaction; insert into tbl_test values(4,'aa',66,'W'); insert into tbl_test values(5,'aa',66,'W'); insert into tbl_t..
Mysql 07 (Index) 01 INDEX - 데이터 베이스 테이블의 검색 성능을 향상시키기 위해 사용되는 데이터 구조 - where 이하 조건절열에 Index로 지정된 열을 사용한다 - Index로 지정된 열은 기본적으로 정렬 처리가 된다 - Unique Index(PK,Unique제약조건시 기본설정됨)와 Non_unique Index로 나눠진다 MYSQL INDEX 종류 - B-Tree :기본값, 대부분의 데이터 Index에 잘 적용되어 사용 - Hash : 해시 함수를 이용한 Index, 정확한 일치 검색에 사용 - Full-text : 전체 텍스트 검색에 사용되는 Index , 텍스트 검색기능 향상 - Spatial : 공간데이터(위도/경도 등)를 처리하기 위한 Index, 지리 정보검색에 유리 제약조건 PK 설정 시 un..
Mysql 06(PK,FK 제약조건, UNIQUE, check) 01 테이블 생성 시 PK 설정 설정 1 create table tbl_Test01 ( id char(10) primary key, name char(10) not null ); 설정2 create table tbl_Test02 ( id char(10), name char(10) not null, primary key(id,name) ); 02 테이블 생성 이후 create table tbl_Test04 ( id char(10), name char(10) not null ); alter table tbl_test04 add constraint PK_tbl_test04 primary key(id); 03 PK 제거 alter table tbl_test01 drop primary key; 04 FK제약조건 ..
Mysql 05 01 insert value값 여러 개 넣기 insert into tbl_copy_buytbl(num,userid,prodname,groupname,price,amount) values (5,'aaa','운동화','의류',1000,1), (6,'aaa','운동화','의류',1000,1), (7,'aaa','운동화','의류',1000,1), (8,'aaa','운동화','의류',1000,1); 02 insert 시 auto_increment : 특정 열에 대해 자동으로 증가하는 순차적인 값을 할당 create table tbl_test (id int primary key auto_increment, name varchar(20), addr varchar(100)); insert into tbl_test(id..
Mysql 04 (group by) 01 group by : 특정 열을 기준으로 데이터를 그룹화 sum select userid,sum(amount*price) as '구매총액' from buytbl group by userid; avg select userid,truncate(avg(amount),2) from buytbl group by userid; truncate(avg(amount),2) = 소수점 2자리 max(), min() select max(height) from usertbl; select min(height) from usertbl; count() select count(*) from usertbl; 02 group by + having select userid, sum(amount) as '총량' from buytbl..
Mysql 03 (Select) *usertbl* 01. Select select * from usertbl; : usertbl의 모든 자료 02 Select where 비교연산자 select * from usertbl where birthyear>=1970; : birthyear가 1970 이상인 모든 자료 select * from usertbl where height =1900 and height>=182; : birthyear가 1970 이상이고, height가 182 이상인 자료 select * from usertbl where birthyear>=1900 or height>=182; : birthyear가 1900 이상이거나, height가 182 이상인 자료 04 In , Like select * from usertbl wh..
Mysql 02 SQL문으로 문제 풀기! 1. testdb 생성 + testdb use 2. tbl_ogu 테이블 생성(id int primary key, name varchar(20), addr varchar(20), phone varchar(20)) *sql문* *결과* 3. tbl_ogu 테이블에 열 추가 (gender varchar(1) null) *sql문* *결과* 4. phone열 제거 *sql문* *결과* 5. tbl_ogu 테이블에 내용 삽입 *sql문* *결과* 6. tbl_ogu 테이블에 내용 수정 (오구 -> 김오구, 북구 -> 남구) *sql문* *결과* 7. 내용 삭제(뚜지 열) *sql문* *결과* 8. testdb export 하기 Navigator - Date Export - testdb체..
Mysql 01 Database란? data - 자료, 단순한 수치 - 객체의 속성을 말함 database - 통합하여 관리되는 데이터의 집합체 - 데이터를 구조화하여 효율적으로 데이터의 삽입, 조회, 삭제가 가능 DBMS란? - data management system - 파일시스템의 단점을 보완하고 대량의 데이터를 보다 효율적으로 관리하고 운영하기 위해서 사용 - sql언어를 사용해서 dbms의 정보를 입력하고 관리하고 추출할 수 있다. DBMS종류 Mysql, MariaDB, SQL server, Oracle, DB2, Access, SQLite Mysql 설치 1. https://dev.mysql.com/downloads/installer/ 접속 2. download 클릭 3. 접속 후 Server only 체크..