当前位置:网站首页>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的读取操作
边栏推荐
- C Primer Plus Chapter 15 (bit operation)
- 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
- C - XOR to all (binary topic)
- 实时时钟 (RTC)
- 求组合数 AcWing 887. 求组合数 III
- Leetcode-3: Longest substring without repeated characters
- 1.15 - input and output system
- 博弈论 AcWing 894. 拆分-Nim游戏
- SQL三种连接:内连接、外连接、交叉连接
- 求组合数 AcWing 889. 满足条件的01序列
猜你喜欢
求组合数 AcWing 889. 满足条件的01序列
Leetcode stack related
求组合数 AcWing 888. 求组合数 IV
Bash exercise 17 writing scripts to install the server side of FRP reverse proxy software
论文阅读报告
20220213-CTF MISC-a_ good_ Idea (use of stegsolve tool) -2017_ Dating_ in_ Singapore
SQL三种连接:内连接、外连接、交叉连接
Leetcode array operation
求组合数 AcWing 887. 求组合数 III
Day 2 document
随机推荐
What's wrong with this paragraph that doesn't work? (unresolved)
SPI 详解
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
4. Object mapping Mapster
2048项目实现
Golang uses context gracefully
Winter messenger 2
[rust notes] 14 set (Part 2)
WordPress switches the page, and the domain name changes back to the IP address
SQLMAP使用教程(一)
Traditional databases are gradually "difficult to adapt", and cloud native databases stand out
Single chip computer engineering experience - layered idea
Data visualization chart summary (II)
MIT-6874-Deep Learning in the Life Sciences Week 7
Navicat連接Oracle數據庫報錯ORA-28547或ORA-03135
SQL三种连接:内连接、外连接、交叉连接
Is it impossible for lamda to wake up?
Matrixdb V4.5.0 was launched with a new mars2 storage engine!
快速使用Amazon MemoryDB并构建你专属的Redis内存数据库
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