当前位置:网站首页>7.Oracle-表结构
7.Oracle-表结构
2022-07-05 06:20:00 【寒叶飘逸_】
- 按下列表结构利用 SQL 语句创建 class,student 两个表。
Class
| 列名 | 数据类型 | 约束 | 备注 |
|---|---|---|---|
| CNO | NUMBER(2) | 主键 | 班号 |
| CNAME | VARCHAR(20) | 班名 | |
| NUM | NUMBER(3) | 人数 |
Student
| 列名 | 数据类型 | 约束 | 备注 |
|---|---|---|---|
| SNO | NUMBER(4) | 主键 | 学号 |
| SNAME | VARCHAR(10) | 唯一 | 姓名 |
| SAGE | NUMBER | 年龄 | |
| SEX | CHAR(2) | 性别 | |
| CNO | NUMBER(2) | 班级号 |
create table class(
cno number(2) primary key,
cname varchar(20),
num number(3)
)
create table student(
sno number(4) primary key,
sname varchar(10),
sage number,
sex char(2),
cno number(2),
unique(sname)
)


- 为 student 表添加一个可以延迟的外键约束,其 CNO 列参照 class 表的 CNO 列。
alter table student
add constraint P_FK foreign key(cno) references class(cno) on delete cascade deferrable

- 为 student 表添加一个可以延迟的外键约束,保证该列表取值在 0~100 之间。
alter table student
add check (sage between 0 and 100)

- 为 student 表的 SAGE 列添加一个检查约束,保证该取值为 “M ”或“F”,且默认值为 “M ”。
alter table student modify(sex char(2) default('m'));
alter table student add check(sex in(‘m’,’f’));

- 利用子查询分别创建一个事务级的临时表和会话级的临时表,其结构与student表结构相同
create global temporary table tran_temp_student on commit delete rows as select * from student;
create global temporary table sess_temp_student on commit preserve rows as select * from student;

- 创建一个student_range表(列、类型与student表的列、类型相同),按学生的年龄分为三个区,低于20岁的学生信息放入part1区,存储在EXAMPLE表空间中;20-30岁的放在part2区,存放在ORCLTBS1表空间中;其他数据放在part3区,存放在ORCLTBS2表空间中
create tablespace ORCLTBS1 datafile 'D:\app\Snakewood\oradata\testdba\ORCLTBS1' size 20m;
create tablespace ORCLTBS2 datafile 'D:\app\Snakewood\oradata\testdba\ORCLTBS2' size 20m;
create tablespace EXAMPLE datafile 'D:\app\Snakewood\oradata\testdba\EXAMPLE' size 20m;
create table student_range partition by range(sage)(partition part1 values less than (20) tablespace example,partition part2 values less than(30) tablespace ORCLTBS1,partition part3 values less than(maxvalue) tablespace ORCLTBS2)as select * from student;


- 创建一个student_list表(列、类型与student表的列、类型相同),按学生性别分为两个区
create table student_list
partition by list(sex)
(
partition student_male values('M') tablespace ORCLTBS1,
partition student_female values('F') tablespace ORCLTBS2
) as
select * from student;

- 将一个保存学生信息的.xls文件转换为.txt文件,根据.txt文件中数据的结构创建一个外部表,实现对.txt的读取操作

边栏推荐
- 【LeetCode】Day95-有效的数独&矩阵置零
- Day 2 document
- Leetcode-556: the next larger element III
- [learning] database: several cases of index failure
- Redis publish subscribe command line implementation
- Sqlmap tutorial (II) practical skills I
- 4. Object mapping Mapster
- 中国剩余定理 AcWing 204. 表达整数的奇怪方式
- Record the process of configuring nccl and horovod in these two days (original)
- liunx启动redis
猜你喜欢

阿里巴巴成立企业数智服务公司“瓴羊”,聚焦企业数字化增长

博弈论 AcWing 891. Nim游戏

Traditional databases are gradually "difficult to adapt", and cloud native databases stand out

Single chip computer engineering experience - layered idea

做 SQL 性能优化真是让人干瞪眼

1.14 - assembly line

Suppose a bank's ATM machine, which allows users to deposit and withdraw money. Now there is 200 yuan in an account, and both user a and user B have the right to deposit and withdraw money from this a

MySQL advanced part 1: View

MySQL advanced part 1: index

Network security skills competition in Secondary Vocational Schools -- a tutorial article on middleware penetration testing in Guangxi regional competition
随机推荐
Doing SQL performance optimization is really eye-catching
2022/6/29-日报
FFmpeg build下载(包含old version)
MySQL advanced part 1: stored procedures and functions
容斥原理 AcWing 890. 能被整除的数
博弈论 AcWing 892. 台阶-Nim游戏
[rust notes] 16 input and output (Part 2)
Winter messenger 2
Niu Mei's math problems
1.13 - RISC/CISC
[rust notes] 16 input and output (Part 1)
高斯消元 AcWing 884. 高斯消元解异或線性方程組
Currently clicked button and current mouse coordinates in QT judgment interface
[rust notes] 14 set (Part 1)
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
Leetcode-22: bracket generation
Sqlmap tutorial (II) practical skills I
Records of some tools 2022
Chapter 6 relational database theory
In depth analysis of for (VaR I = 0; I < 5; i++) {settimeout (() => console.log (I), 1000)}