佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1631|回复: 1

Oracle primary key and foreign key

[复制链接]
发表于 17-2-2008 09:01 PM | 显示全部楼层 |阅读模式
如果我有3个table..table1 ,table 2, table 3....table3 里面有table 1 和 table 2 的 primary key...如何将这两个priamry key combine as table3 的primary key....create table 3 的 statement 要如何写???谢谢。。
回复

使用道具 举报


ADVERTISEMENT

发表于 18-4-2008 09:24 AM | 显示全部楼层

回复 1# keeplwk 的帖子

也许你已知方法...

通常我们是用composite key 在 table 3.

如以下:

create table tab1 ( col1 varchar2(10));

alter table tab1 add constraint PK_TAB1
primary key (col1) using index;

create table tab2( col2 varchar2(10));

alter table tab2 add constraint PK_TAB2
primary key (col2) using index;

create table tab3 (col1 varchar2(10), col2 varchar2(10));

alter table tab3 add constraint PK_TAB3
primary key (col1,Col2)
using index;

--Optional for foreign key
--因为有些人因为 performance issue 不用 foreign key constraint
--如可以,建议用 foreign key constraint 来管理 data integrity

alter table tab3 add constraint FK_TAB3_COL1
foreign key (col1)
references tab1 (col1);

alter table tab3 add constraint FK_TAB3_COL2
foreign key (col2)
references tab2 (col2);
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 2-1-2026 06:05 AM , Processed in 0.116587 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表