
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即外码,
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)