|
查看: 1630|回复: 1
|
Oracle primary key and foreign key
[复制链接]
|
|
|
|
如果我有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 要如何写???谢谢。。 |
|
|
|
|
|
|
|
|
|
|
发表于 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); |
|
|
|
|
|
|
|
|
| |
本周最热论坛帖子
|