본문 바로가기

DataBase29

[MariaDB] 컬럼의 데이터 삭제 / delete문 데이터 삭제 / update문 데이터 수정 / delet문 문법 DELETE FROM [ 테이블 ] WHERE [ 조건 ] delete from 테이블명 where 컬럼명 between ?(조건 1) and ?(조건 2) update문 문법 Update 테이블명 set 컬럼명 = '수정 후 데이터' where 컬럼명 = '수정 전 데이터' 2022. 10. 25.
[MariaDB] 날짜 관련 명령어 now() 현재 날짜 및 시간 정보 출력 / sysdate(), current_timestamp() 현재 날짜 및 시간 정보 출력 / curdate(), curtime() 시간 정보 출력 / 현재 날짜에 2일 더하기 date_add( 기준 날짜,.. now(), 현재 날짜 및 시간 정보 출력 select now(); sysdate(), current_timestamp(), 현재 날짜 및 시간 정보 출력 select sysdate(), current_timestamp(); curdate(), curtime(), 시간 정보 출력 select curdate(), curtime(); 현재 날짜에 2일(2 day) 더하기( date_add == adddate ) select now(), date_add( now(), interval 2 day ); 현재 날짜에 2달(2 month) 더하기( date_add == adddate ) select now(), date_add( now(), interval 2 month ); 현재 날짜에 2달 빼기( date_sub.. 2022. 10. 20.
[MariaDB] 문자열 관련 명령어 / ascii 아스키 코드 값 출력 / length 바이트로 계산된 문자열 길이 출력 / char_length 문자열의 글자수 출력 / concat 문자열 결합 / instr 문자열 찾기, 1부터 시작, 없으면 0 .. ascii(), 아스키 코드 값 출력 select ascii('A'), ascii('a'); length("문자"), 바이트(byte)로 계산된 문자열의 길이를 출력 select length( 'abc' ); length 응용 컬럼의 문자열의 길이를 추가해서 부서번호 20번의 사원이름과 같이 출력 select ename, length( ename ) from emp where deptno=20; char_length("문자"), 문자열의 글자수를 출력 select length( '테스트' ), char_length( '테스트' ); char_length 응용 1 문자열의 글자 수가 4인 사원이름을 출력하기 select ename from emp where char_length(ename) = 4; cha.. 2022. 10. 20.
[MariaDB] 연산 관련 명령어 / abs 절댓값 / ceil 올림 / floor 내림 / round 반올림 / truncate 숫자 버림 / power 제곱 / %, mod 나머지 / greatest 최댓값 / least 최솟값 연산 관련 함수 참고 사이트 Numeric Functions mariadb.com abs( 숫자 ), 절댓값 출력 select abs(123), abs(-123); ceil(실수), 올림 select ceil(4.4), ceil(4.5), ceil(4.6); floor(실수), 내림 select floor(5.6), floor(6.7); round(실수), 반올림 select round(4.5), round(4.3); truncate(숫자, 버릴 구간), 숫자 버림 select truncate(999.999, 0); select truncate(999.999, -2); power(숫자, 제곱), 제곱 select power(2,2); %, mod(숫자, 숫자) select 5 % 2, mod(5,2); .. 2022. 10. 20.
[MariaDB] 제약조건 수정 요약본 / Primary Key 추가, 삭제/ not null 설정, 해제 / unique 설정, 해제 / foregin key 설정, 해제 / 기존 생성된 테이블에 제약조건(Primary key 추가, 삭제 등) 추가할 때 사용 Primary Key 추가(괄호 주의) alter table 테이블명 add constraint primary key (컬럼명); Primary Key 삭제(괄호 주의, not null 별도 해제 필요) alter table 테이블명 drop primary key; not null 설정(자료형 명시 중요) alter table 테이블명 modify 컬럼명 자료형() not null; not null 해제(자료형 명시 중요) alter table 테이블명 modify 컬럼명 자료형(); unique 설정(괄호 주의) alter table 테이블명 add constraint unique (컬럼명); unique 해제 alt.. 2022. 10. 19.
[MariaDB] default ,테이블 생성 시 컬럼의 default(기본 값) 설정 /upadte set , 테이블 컬럼의 데이터 수정 /not null, null 값을 허용하지 않는 컬럼 /ERROR 1048 (23000) : Column cannot be null /unique 중복 데이터를 허.. default ,테이블 생성 시 컬럼의 default(기본 값) 설정 create table detp1 ( -> deptno int(2) default 90, -> dename varchar(14), -> loc varchar(13) -> ); 테이블 데이터 삽입 예제 1 insert into dept1 values(10, '개발부', '서울'); 테이블 데이터 null 값 삽입 2 insert into dept1 values(null, '개발부', '서울'); 테이블 데이터 null 값 삽입 예제 3 insert into dept1 values(default, '개발부', '서울'); insert into dept1 values ( default, '연구부', '대전'); update ~ set ,테이.. 2022. 10. 19.