05-18 22:35
Notice
Recent Posts
Recent Comments
Link
관리 메뉴

코딩일지

SQL 문법 - 테이블 기본키, 외래키 설정 & 테이블 스페이스 생성 본문

코딩/데이터베이스

SQL 문법 - 테이블 기본키, 외래키 설정 & 테이블 스페이스 생성

여유거북이 2016. 10. 30. 14:50

간단 용어정리 ))

 

기본키 -> 후보키 중 의미 있다고 생각하는 키를 기본키로 설정한다. 기본키는 NULL이 될 수 없다.

외래키 -> 외래키는 참조되는 테이블의 기본키여야 한다.

기본키가 존재하고 이를 참조하는 테이블은 참조되는 테이블이라고 하고, 외래키가 존재하는 테이블은 참조하는 테이블이라고 한다.


 

 

 

<테이블 생성 시 기본키 설정>

 

create table class

(

class_id varchar2(10) not null,

year int,

semester int,

enroll int,

division int,

classroom varchar2(10)

 

constraint pk_class primary key (class_id)

);

 

 

 

<테이블 생성 시 기본키와 외래키 설정>

 

create table class

(

class_id varchar2(10) not null,

course_id varchar2(10) not null,

pro_id varchar2(10) not null,

year int,

semester int,

enroll int,

division int,

classroom varchar2(10)

 

constraint pk_class primary key (class_id),

constraint fk_class1 foreign key (course_id),

constraint fk_class2 foreign key (pro_id)

);

 

 

 

<테이블스페이스 생성>  -> system 계정에서만!

 

create tablespace space01

datefile 'D:/oracle/my_data/data01.dbf size 3M;

 

 

 

<테이블스페이스 변경>

 

alter tablespace space01

add datefile 'D:/oracle/my_data/data02.dbf size 5M;

 

 

<테이블스페이스 삭제>

 

drop tablespace space01;

 

<테이블스페이스 조회>

 

select tablespace_name, file_name from dba_data_files;

 

 

 

Comments