oracle绑定主键,oracle添加主键的四种方法:

oracle添加主键的四种方法:

列级,表级建立主键

drop table constraint_test;

1.create table constraint_test

( name_id number not null constraint cons_name_id primary key,

old number )

2.create table constraint_test

( name_id number  primary key,

old number )

drop table constraint_test;

3.create table constraint_test

(

name_id number not null,

old number  ,

constraint cons_name_id primary key ( name_id )

);

drop table constraint_test;

4.create table constraint_test

(

name_id number not null,

old number

);

alter table constraint_test add constraint cons_name_id primary key ( name_id );

外键

drop table course ;

drop table students ;

create table students

(code number  ,

name varchar2(10),

country varchar2(30)

);

alter table students add constraint pk_st_cod primary key ( code);

insert into students values(0001,'zhangsan','shanghai');

insert into students values(0002,'lisi','beijing');

insert into students values(0003,'wangwu','guangzhou');

create table course

(id number,

code  number,

name varchar2(10),

subject varchar2(30)

);

alter table course  add constraint pk_co_id primary key ( id);

alter table course  add constraint fk_co_st foreign key ( code) references  students(code);

alter table students add foreign key pk_co_id on id;

inser into course(id,code,name,subject) values(1,001,'zhangsan','yuwen');

inser into course(id,code,name,subject) values(2,001,'zhangsan','shuxue');

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/24179204/viewspace-2127542/,如需转载,请注明出处,否则将追究法律责任。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值