Oracle数据库建表+添加数据练习
SQL脚本:
--建表
--student表+注释
create table student(
sno varchar2(3) not null,
sname varchar2(9) not null,
ssex varchar2(3) not null,
sbirthday date,
sclass varchar2(5),
constraint pk_student primary key(sno)
);
comment on column student.sno is '学号(主键)';
comment on column student.sname is '学生姓名';
comment on column student.ssex is '学生性别';
comment on column student.sbirthday is '学生出生年月日';
comment on column student.sclass is '学生所在班级';
--course表+注释
create table course(
cno varchar2(5) not null,
cname varchar2(15) not null,
tno varchar2(3) not null,
constraint pk_course primary key(cno)
);
comment on column course.cno is '课程编号(主键)';
comment on column course.cname is '课程名称';
comment on column course.tno is '教工编号(外键)';
--score表+注释
create table score(
sno varchar2(3) not null,
cno varchar2(5) not null,
degree number(4,1),
constraint pk_score primary key(sno,cno)
);
comment on column score.sno is '学号(主键)';
comment on column score.cno is '课程编号(主键)';
comment on column score.degree is '成绩';
--teacher表+注释
create table teacher(
tno varchar2(3) not null,
tname varchar2(9) not null,
tsex varchar2(3) not null,
tbirthday date,
prof varchar2(9),
depart varchar2(15) not null,
constraint pk_teacher primary key(tno)
);
comment on column teacher.tno is '教工编号(主键)';
comment on column teacher.tname is '教工姓名';
comment on column teacher.tsex is '教工性别';
comment on column teacher.tbirthday is '教工出生年月';
comment on column teacher.prof is '职称';
comment on column teacher.depart is '教工所在单位';
--添加外键
alter table course add constraint fk_tno foreign key(tno) references teacher(tno);
alter table score add constraint fk_sno foreign key(sno) references student(sno);
alter table score add constraint fk_cno foreign key(cno) references course(cno);
--添加数据
--Student表
insert into student(sno,sname,ssex,sbirthday,sclass) values(108,'曾华','男',to_date('1977-09-01','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(105,'匡明','男',to_date('1975-10-02','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(107,'王丽','女',to_date('1976-01-23','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(101,'李军','男',to_date('1976-02-20','yyyy-mm-dd'),95033);
insert into student(sno,sname,ssex,sbirthday,sclass) values(109,'王芳','女',to_date('1975-02-10','yyyy-mm-dd'),95031);
insert into student(sno,sname,ssex,sbirthday,sclass) values(103,'陆君','男',to_date('1974-06-03','yyyy-mm-dd'),95031);
--teacher表
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(804,'李诚','男',to_date('1958/12/02','yyyy-mm-dd'),'副教授','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(856,'张旭','男',to_date('1969/03/12','yyyy-mm-dd'),'讲师','电子工程系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(825,'王萍','女',to_date('1972/05/05','yyyy-mm-dd'),'助教','计算机系');
insert into teacher(tno,tname,tsex,tbirthday,prof,depart) values(831,'刘冰','女',to_date('1977/08/14','yyyy-mm-dd'),'助教','电子工程系');
--course表(添加外键后要先填teacher表中数据去满足外键约束)
insert into course(cno,cname,tno) values('3-105','计算机导论',825);
insert into course(cno,cname,tno) values('3-245','操作系统',804);
insert into course(cno,cname,tno) values('6-166','数字电路',856);
insert into course(cno,cname,tno) values('9-888','高等数学',831);
--score表(添加外键后要先填Student,course表中数据去满足外键约束)
insert into score(sno,cno,degree) values(103,'3-245',86);
insert into score(sno,cno,degree) values(105,'3-245',75);
insert into score(sno,cno,degree) values(109,'3-245',68);
insert into score(sno,cno,degree) values(103,'3-105',92);
insert into score(sno,cno,degree) values(105,'3-105',88);
insert into score(sno,cno,degree) values(109,'3-105',76);
insert into score(sno,cno,degree) values(101,'3-105',64);
insert into score(sno,cno,degree) values(107,'3-105',91);
insert into score(sno,cno,degree) values(108,'3-105',78);
insert into score(sno,cno,degree) values(101,'6-166',85);
insert into score(sno,cno,degree) values(107,'6-166',79);
insert into score(sno,cno,degree) values(108,'6-166',81);
Student表 Course表
Score表
Teacher表
Oracle数据库建表+添加数据练习的更多相关文章
- PowerDesigner连接Oracle数据库建表序列号实现自动增长
原文:PowerDesigner连接Oracle数据库建表序列号实现自动增长 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties — ...
- T-SQL - query01_创建数据库|创建表|添加数据|简单查询
时间:2017-09-29 整理:byzqy 本篇以"梁山好汉花名册"为例,记录MS SQLServer T-SQL语句的使用,包含命令: 创建数据库 | 删除数据库 创建表 | ...
- Oracle数据库在给表添加字段的sql中用comment报错
原因:不同于mysql,Oracle数据库在添加表字段时不能直接用comment,而是单独写一个sql语句,如下: alter table SYS_USER add SENDMSG_LASTTIME ...
- Oracle建表添加数据
- Oracle数据库建表并用SQL编程分等级
--创建学生表create table XS_543 ( XH char(6) not null , XM varchar2(20) not null, ZYM varchar2(10), XB ch ...
- oracle数据库建表
create or replace directory dumpdir as 'E:\oracle\dumpdir';create temporary tablespace ydxt_temp tem ...
- OREACLE 数据库建表 添加判断表是否存在 不存在则新建
declare cnt number; begin ---查询要创建的表是否存在 select count(*)into cnt from user_tables where table_n ...
- oracle数据库建表设置自增主键
create sequence userlogin_ID increment by 1 start with 1 minvalue 1 maxvalue 9999999999999999 nocach ...
- 定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表
最近项目中有一种需求: 大致需求是这样的 通过给定的 用户名和密码 要定时从远程的数据库中取数据,然后把取出来的数据插入或更新本地的oracle数据库的表 项目的结构式struts1 hibernat ...
随机推荐
- decimalFormat("#","##0.00") java
importjava.text.DecimalFormat; publicclassTestNumberFormat{ publicstaticvoidmain(String[]args){ doub ...
- oracle创建用户、授予权限及删除用户
创建用户 oracle对表空间 USERS 无权限 alter user 用户名 quota unlimited on users; //创建临时表空间 create temporary ta ...
- 使用 IntraWeb (43) - 测试读取 SqLite (二)
一般情况下, 数据源相关控件应该有数据模块中统一管理, 这也方便其他窗体调用; UserSessionUnit 就是一个现成的数据模块. 现在把数据源相关控件放在 UserSessionUnit 的窗 ...
- unreal3脚本stacktrace的问题
在unrealscript里获取调用栈,有下面两函数: /** * Dumps the current script function stack to the log file, useful * ...
- 通过pycurl模块添加put和delete请求
原文链接: http://anupamshakya.blogspot.com/2013/07/implementation-of-put-and-delete-in.html
- C#事务的使用
1.引入相应的命名空间 using System.Transactions; 2.代码事例(using (TransactionScope ts = new TransactionScope())) ...
- Git使用实例分析
记录下James工作中遇到的问题: 1. 在app目录下提交.cfg特制化文件,此时Git和Gerrit结合使用: 2. 对修改文件追加提交: 3. 查看当前目录的所有分支,包括:本地分支和远程分支: ...
- mysql mha 主从自动切换 高可用
mha(Master High Availability)目前在MySQL多服务器(超过二台),高可用方面是一个相对成熟的解决方案. 一,什么是mha,有什么特性 1. 主服务器的自动监控和故障转移 ...
- heartbeat安装与配置
Hearbeat和keepalived区别 Keepalived使用的vrrp协议方式,虚拟路由冗余协议 (Virtual Router Redundancy Protocol,简称VRRP): He ...
- RDBMS,memcache
1.RDBMS即关系数据库管理系统(Relational Database Management System),是将数据组织为相关的行和列的系统,而管理关系数据库的计算机软件就是关系数据库管理系统, ...