最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

Oracle建库流程例子

来源:动视网 责编:小采 时间:2020-11-09 12:03:12
文档

Oracle建库流程例子

Oracle建库流程例子:sqlplus system/system@orcl --连接SQLgt;ed a --创建sql文本SQLgt;get a --把a.sql载入缓存SQLgt;/create temporary tabl sqlplus system/system@orcl --连接 SQL>ed a --创建sql文本SQL>get a --把a.sql
推荐度:
导读Oracle建库流程例子:sqlplus system/system@orcl --连接SQLgt;ed a --创建sql文本SQLgt;get a --把a.sql载入缓存SQLgt;/create temporary tabl sqlplus system/system@orcl --连接 SQL>ed a --创建sql文本SQL>get a --把a.sql


sqlplus system/system@orcl --连接SQLgt;ed a --创建sql文本SQLgt;get a --把a.sql载入缓存SQLgt;/create temporary tabl

sqlplus system/system@orcl --连接

SQL>ed a --创建sql文本
SQL>get a --把a.sql载入缓存
SQL>/

create temporary tablespace sa_temp --临时表空间
tempfile 'E:\dbf\sa_temp.dbf'
size 10m
autoextend on;

create tablespace sa_space --表空间
logging
datafile 'E:\dbf\sa_space.dbf'
size 20m --20M
autoextend on; --自动增长


create user sa identified by sa --创建用户 使用对应的表空间
default tablespace sa_space
temporary tablespace sa_temp;


grant connect,resource,dba to sa; --授予连接 、dba权限给用户


conn sa/sa --角色sa


--创建学员信息表
create table studentInfo(
stuId number primary key not null,
tel nvarchar2(15),
sex char(2) not null,
schoolTime date not null,
email nvarchar2(50) not null,
remark nvarchar2(500) not null
);


--创建课程表
create table Course(
courseId number primary key not null,
courseCode nvarchar2(15), --课程代码
courseName nvarchar2(50)
);


--创建学员与课程关系表(多对多)
create table stdent_course(
courseId number not null,
stuId number not null
);


--创建序列
create sequence seq_studentInfo_stuId --学员序列
increment by 1 -- 每次加1
start with 1 -- 从1开始计数
nomaxvalue -- 不设置最大值
nocycle -- 一直累加,,不循环
nocache -- 不建缓冲区


create sequence seq_course_courseId --课程序列
increment by 1 -- 每次加1
start with 1 -- 从1开始计数
nomaxvalue -- 不设置最大值
nocycle -- 一直累加,不循环
nocache -- 不建缓冲区

--创建触发器
create or replace trigger tri_studentInfo_stuId --学员主键自增
before
insert on studentInfo for each row
begin
select seq_studentInfo_stuId.nextval into :New.stuId from dual;
end;


create or replace trigger tri_course_courseId --课程主键自增
before
insert on course for each row
begin
select seq_course_courseId.nextval into :New.courseId from dual;
end;

--建立课程表主外建关系
alter table stdent_course add constraint fk_stdentcourse_courseId
foreign key(courseId) references course(courseId);

--建立学员主外建关系
alter table stdent_course add constraint fk_stdentcourse_courseId
foreign key(stuId) references studentId(stuId);


--sql测试
insert into studentinfo(tel,sex,schooltime,email,remark)
values('123456','男',to_date('2011-01-12','yyyy-MM-dd'),'ss@ww.com','爱是刚');
insert into studentinfo(tel,sex,schooltime,email,remark)
values('111111','男',to_date('2011-02-12','yyyy-MM-dd'),'ss1@ww.com','爱是刚111');

insert into course(coursecode,coursename)values('001','语文');
insert into course(coursecode,coursename)values('002','数学');

insert into stdent_course (stuid,courseid)values(1,1);
insert into stdent_course (stuid,courseid)values(1,2);
insert into stdent_course (stuid,courseid)values(2,1);

select * from studentinfo;
select * from course;
select * from stdent_course;

文档

Oracle建库流程例子

Oracle建库流程例子:sqlplus system/system@orcl --连接SQLgt;ed a --创建sql文本SQLgt;get a --把a.sql载入缓存SQLgt;/create temporary tabl sqlplus system/system@orcl --连接 SQL>ed a --创建sql文本SQL>get a --把a.sql
推荐度:
标签: 步骤 过程 数据库
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top