度量快速开发平台-专业、快速的软件定制快开平台

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 部件 流程 SQL
查看: 2510|回复: 7
打印 上一主题 下一主题

[分享] oracle添加主键的四种方法

[复制链接]

542

主题

5916

帖子

1万

积分

作者

Rank: 7Rank: 7Rank: 7

积分
13589
楼主
 楼主| 发表于 2020-2-7 14:00:44 | 显示全部楼层
回复 支持 反对

使用道具 举报

542

主题

5916

帖子

1万

积分

作者

Rank: 7Rank: 7Rank: 7

积分
13589
沙发
发表于 2020-7-26 14:33:05 | 显示全部楼层 回帖奖励 |倒序浏览 |阅读模式
racle添加
主键的四种方法:

列级,表级建立主键

drop table constraint_test;

1.create table constraint_test

( name_id number not null constraint cons_name_id primarykey,

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 studentsvalues(0001,'zhangsan','shanghai');

insert into studentsvalues(0002,'lisi','beijing');

insert into studentsvalues(0003,'wangwu','guangzhou');



create table course

(id number,

code  number,

name varchar2(10),

subject varchar2(30)

);

alter table course  add constraint pk_co_idprimary key ( id);

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

alter table students add foreign key pk_co_id onid;

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

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

分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

542

主题

5916

帖子

1万

积分

作者

Rank: 7Rank: 7Rank: 7

积分
13589
板凳
 楼主| 发表于 2020-7-26 14:33:28 | 显示全部楼层
回复 支持 反对

使用道具 举报

542

主题

5916

帖子

1万

积分

作者

Rank: 7Rank: 7Rank: 7

积分
13589
地板
 楼主| 发表于 2020-7-28 17:28:41 | 显示全部楼层
回复 支持 反对

使用道具 举报

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

本版积分规则

手机版|小黑屋|玉祥公司客服-玉祥集团客服  本站关键词:快速开发平台

GMT+8, 2024-5-9 08:24 , Processed in 0.135979 second(s), 24 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

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