oracle数据库创建表实验

本文详细描述了一个关于使用Oracle12C和PL/SQL语言进行数据库操作的实验,涉及创建StudentInfo和ScoreInfo表,修改数据类型,删除字段,以及编写和调试相关代码的过程。
摘要由CSDN通过智能技术生成

目录

1.实验目的及要求

2.实验实训设备或环境要求

3.实验实训内容及方法步骤

实验实训内容

创建StudentInfo表。

创建ScoreInfo表。

将StudentInfo表的Name字段的数据类型改为char(12)。

将StudentInfo表的Address字段删除。

在StudentInfo表中增加名为Phone的字段,数据类型为char(20)。

删除StudentInfo表。

实验步骤

创建StudentInfo表。

2.创建ScoreInfo表。

3.将StudentInfo表的Name字段的数据类型改为char(12)。

4.将StudentInfo表的Address字段删除。

5.在StudentInfo表中增加名为Phone的字段,数据类型为char(20)。

6.删除StudentInfo表。

4.实验实训结果


创建表实验

1.实验目的及要求

(1)理解数据库和表的基本概念

(2)掌握使用PL/SQL语言创建表的操作,具备编写和调试创建表、修改表、删除表的代码的能力。

2.实验实训设备或环境要求

pc机、Oracle 12C

3.实验实训内容及方法步骤

实验实训内容:设计性实验——使用PL/SQL语句创建表、修改表、删除表。

在ora数据库中分别创建一个StudentInfo表(学生信息表)和ScoreInfo表(成绩信息表),表结构分别如下所示。

表1 StudentInfo表的表结构

列名

数据类型

允许null值

是否主键

说明

StudentID

Varchar2(6)

主键

学号

Name

Varchar2(12)

姓名

Sex

Varchar2(3)

性别

Birthday

date

出生日期

Speciality

Varchar2(18)

专业

Address

Varchar2(30)

家庭地址

表2 ScoreInfo表的表结构

列名

数据类型

允许null值

是否主键

说明

StudentID

Varchar2(6)

主键

学号

CourseID

Varchar2(4)

课程号

Grade

Number

成绩

实验实训内容

编写和调试创建表、修改表、删除表的代码,完成以下操作。

  1. 创建StudentInfo表。
  2. 创建ScoreInfo表。
  3. 将StudentInfo表的Name字段的数据类型改为char(12)。
  4. 将StudentInfo表的Address字段删除。
  5. 在StudentInfo表中增加名为Phone的字段,数据类型为char(20)。
  6. 删除StudentInfo表。

实验步骤

  1. 创建StudentInfo表。
create table StudentInfo

(

StudentID varchar2(6) not null primary key,

Name varchar2(12) not null ,

Sex varchar2(3) not null,

Birthday date not null,

Speciality varchar2(18) null,

Address varchar2(30) null

);

//添加说明注释

comment on column StudentInfo.StudentInfo is '学号';

comment on column StudentInfo.Name is '姓名';

comment on column StudentInfo.Sex is '性别';

comment on column StudentInfo.Birthday is '出生日期';

comment on column StudentInfo.Speciality is '专业';

comment on column StudentInfo.Address is '家庭地址';
2.创建ScoreInfo表。
create table ScoreInfo

(

StudentID varchar2(6) not null primary key,

CourseID varchar2(4) not null,

Grade number not null

);

//添加说明注释

comment on column ScoreInfo.StudentID is '学号';

comment on column ScoreInfo.CourseID is '课程号';

comment on column ScoreInfo.Grade is '成绩';
3.将StudentInfo表的Name字段的数据类型改为char(12)。
alter table StudentInfo

modify(Name char(12));
4.将StudentInfo表的Address字段删除。
alter table StudentInfo

drop column Address;
5.在StudentInfo表中增加名为Phone的字段,数据类型为char(20)。
alter table StudentInfo

add Phone char(20);

comment on column StudentInfo.Phone is '电话';
6.删除StudentInfo表。
drop table StudentInfo;

4.实验实训结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值