태터데스크 관리자

도움말
닫기
적용하기   첫페이지 만들기

태터데스크 메시지

저장하였습니다.

[SQL] 기본키와 외래키 설정 예

1. 릴레이션의 애트리뷰트와 데이터타입

CREATE TABLE board_pos (
 num int(11) not null auto_increment,
 name varchar(15) NULL,
 email varchar(30) NULL ,
 PRIMARY KEY ( num )
);



2. board_pos 의 num 필드를 참조하는 board_repl의 board_num 필드에 외래키 설정하는 법
필드에 직접 기록하는 방법과 필드 설정 후 마지막 라인에 별도로 추가하는 방법 두가지가 있음.
---필드에 추가하는 방법 ----
create table board_repl(
num int not null primary key,
board_num int not null REFERENCES board_pos(num),
contonts varchar(100) not null,
reg_date datetime not null,
name varchar(20)not null
);

---필드와 별도로 추가하는 방법---
create table board_repl(
num int not null primary key,
board_num int not null,
contonts varchar(100) not null,
reg_date datetime not null,
name varchar(20)not null,
FOREIGN KEY(board_num) REFERENCES board_pos(num)
);



top

Trackback Address :: http://www.ssial.com/trackback/71 관련글 쓰기

  1. Chanel Outlet 2011/09/17 21:31 댓글주소 | 수정/삭제 | 댓글

    Time is what you make of it.

  2. Burberry Bags 2011/10/13 17:26 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog! From time to time students want to cognitive the keys of productive literary essays composing. Your first-class knowledge about this good post can become a proper basis for such people. Thanks.

  3. Coach Outlet Online 2011/11/15 12:52 댓글주소 | 수정/삭제 | 댓글

    I'm happy I found this blog ! It's very good and thank you for sharing it !

Write a comment