当前位置:首页>维修大全>综合>

关系模型如何找主码和外码

关系模型如何找主码和外码

更新时间:2023-10-01 04:31:00

关系模型如何找主码和外码

1、创建主键测试表test_key_p, create table test_key_p(id number, class_id number)

; 2、创建两一个主键测试表test_key_f,class_id字段作为test_key_p表的外键, create table test_key_f(class_id number, class_name varchar2(20))

; 3、编写sql,添加主键、外键, -- Create/Recreate primary, unique and foreign key constraints alter table TEST_KEY_P add constraint p_key1 primary key (ID)

; alter table TEST_KEY_P add constraint f_key2 foreign key (CLASS_ID) references test_key_f (CLASS_ID)

; 4、查看主键、外键信息,ID为primary即主码,CLASS_ID为foreign即外码,

更多栏目