본문 바로가기

DB/Oracle

오라클/ 기본 쿼리문 연습.

create table tb_test(test_a varchar2(100) not null default 'a')

drop table tb_test

delete from tb_test where test_a = 'a'


select * from tb_test 

select count(*) from tb_test

insert into tb_test(test_a, test_b,test_date) values ('a','b',to_date('data','format'))

update tb_test set test_a = 'b'where test_b = 'b'


alter table tb_test add constraint tb_test_pk primary key(test_a)

alter table tb_test add constraint tb_test_fk foreign key(test_a) references tb_test2(test_a)


*check - 해당 컬럼에 이 값이 아니면 삽입이 안 되게 체크. 다른 값이 들어가면 에러발생.


create table tb_test (

test_a varchar2(100) ,

test_b varchar2(100)

constraint test_a_check (gender in('a','b')

)


*default : 값이 삽입 되지 않았을때 기본적으로 입력되게 역할. %주의 반드시 null or not null 다음에 위치

create table tb_test (

test_a varchar2(100) default 'a',

test_b varchar2(100)

constraint test_a_check (gender in('a','b')

)

alter table tb_test modify test_a default 'a';

alter table tb_test add test_b varchar2(100) 'b';


테이블 복사

%제약사항 존재. -원본 테이블의 인덱스는 복사 안 됨. long타입 복사 안 됨. null, not null만 복사됨.

create table tb_test2 as select * tb_test 

'DB > Oracle' 카테고리의 다른 글

분석함수 팁  (0) 2016.08.31
오라클 정규식 이용하여 문자열 자르기  (0) 2016.03.30
테이블의 테이블 스페이스 일괄 변경  (0) 2015.11.06
db 암호화  (0) 2015.04.27
[ibatis/mybatis] RDBMS별 like문 사용법.  (0) 2013.06.11