Oracle Database experiment to establish a database

The real test day period:    2019 Nian   09 Yue   24-   day

Experimental Report Date:    2019   Nian   09 Yue   28 Ri

 

First, the      purpose of the experiment

Familiar oracle environment;

And the establishment of basic proficiency in database tables using PL-SQL.

Use PL / SQL developer to operate the database.

Master SQL to build relationships, and additions and deletions to the data.

Second, the      experimental environment

Windows10 Pro

Oracle database 11g

PL/SQL Developer 13

Third, the      experimental content

Understand the use of SQL PLUS

Use PL / SQL developer graphical interface, various establishing relations of library management database orcl

Enter valid data in a relational established in

Delete the above relationship

In PL / SQL developer build each relationship orcl database with SQL code

Completion data by using SQL code, delete, change

Fourth, the      experimental procedures

  • SYSTEM log on to the database

Open the PL / SQL developer, the user: the SYSTEM, password: orcl, orcl log database, shown in Figure 1:

 

1 Log Database

  •  registered user

Open the Users folder, create a new user. Username: S512017 ****, password as orcl, and gives connect and dba permissions.

 

Figure 2 , 3 register new users and assigning privileges

  • New user logs back on to the database

       

4 new user login database

  • Establishment of a database table

Open the tables folder. Establish the following relationship:

Library Classification (CLC books, class name)

Bibliography (ISBN, title, author, publishing units, unit price, book CLC)

Book (Book Number, ISBN, whether the loan, notes)

Readers (library card number, name, affiliation, gender, address, telephone number, identity card number)

Lending (Loan serial number, library card number, book number, borrowing date, return date, fine words, notes)

Fine classification (CLC fine, fine name, penalties)

Reservation (reservation serial number, library card number, ISBN, appointment)

(1) the establishment of a graphical interface:

 

 

FIG 5 setting table

 

 

FIG 6 setting table attribute columns

 

 

FIG. 7 is provided in the primary key table

Books classification table is created, the remaining build tables of the same reason can be built as follows (the first to set the table name (the Name), followed by a setting mode (the Columns), the key is provided (Keys), setting prescribed conditions (the Check ), if not it is not necessary to define related items):

bibliography:

 

 

books:

 

 

 

 

reader:

 

 

 

 

Lending:

 

 

 

 

Fine Category:

 

 

 

reservation:

 

 

(2) established by the SQL statement:

Book Category:

create table books classification (

Book DOI varchar2 (3) primary key,

Class name varchar2 (10) not null

);

bibliography:

create table books (

ISBN   varchar2(20) primary key,

Title varchar2 (20) not null,

Author varchar2 (20) not null,

Publisher varchar2 (30),

Price number (10,2),

Book DOI varchar2 (3),

foreign key (Book DOI) references books classification (Book DOI)

);

books:

create table books (

Book Number varchar2 (7) primary key,

ISBN   varchar2(20),

Whether lending varchar2 (2),

Remarks varchar2 (60),

foreign key (ISBN) references bibliography (ISBN),

check (if lending = 'yes' is = lent or 'No')

);

reader:

create table reader (

Library card varchar2 (8) primary key,

Name varchar2 (10) not null,

Unit varchar2 (30),

Sex varchar2 (2),

Address varchar2 (30),

Phone char (11),

ID No. varchar2 (18),

check (sex in ( 'male', 'female')),

check (regexp_like (telephone, '[0-9] {11}')),

check (regexp_like (ID number, '[0-9] {15}')

or regexp_like (ID number, '[0-9] {17} [0-9, X]'))

);

Lending:

create table borrow (

Lending serial number primary key,

Library card varchar2 (8) not null,

Book Number varchar2 (8) not null,

Borrowing date date not null,

Return date date,

Fine classification number,

Remarks varchar2 (60),

foreign key (library card number) references readers (library card number),

foreign key (ISBN) references books (ISBN)

);

Fine Category:

create table fine classification (

Fine classification number primary key,

Fine name varchar2 (8) not null,

Penalty number not null

);

reservation:

create table reservation (

Reservation serial number primary key,

Library card varchar2 (8),

ISBN   varchar2(20),

Appointment date not null,

foreign key (library card number) references readers (library card number),

foreign key (ISBN) references bibliography (ISBN)

);

  1. Each relationship between the input data are as follows:

Library Classification (CLC books, class name)

Book Classification

The class name

100

literature

200

Science and Technology

300

philosophy

Bibliography (ISBN, title, author, publishing units, unit price, book CLC)

ISBN

Title

Author

Publisher

unit price

Book Classification

7040195836

Introduction to Database Systems

Wang Shan

Higher Education Press

39.00

200

9787508040110

Dream of Red Mansions

Cao Xueqin

People's Publishing House

20.00

100

9787506336239

Dream of Red Mansions

Cao Xueqin

Writers Publishing House

34.30

100

9787010073750

Road of Mind

Zhang Liwen

People's Publishing House

33.80

300

 

Book (Book Number, ISBN, whether the loan, notes)

Book Number

ISBN

Whether loan

Remark

2001231

7040195836

no

 

2001232

7040195836

Yes

 

1005050

9787506336239

no

 

1005063

9787508040110

Yes

 

3007071

9787010073750

Yes

 

Readers (library card number, name, affiliation, gender, address, telephone number, identity card number)

Library card number

Full name

unit

gender

address

contact number

Identity card number

20051001

Faye

C-COR Mianyang large of Computer Science

Female

..

20062001

Zhangjiang

Mianyang Central Hospital

male

..

20061234

GJM

Jiangyou 305

male

..

..

..

20071235

Li Xiaoming

Industrial and Commercial Bank of Chengdu, Sichuan

male

..

..

..

20081237

Zhao Xin

Sichuan Guangyuan Guangyuan middle school

Female

..

..

..

Lending (Loan serial number, library card number, book number, borrowing date, return date, fine words, notes)

Lending serial number

Library card number

Book Number

Borrowing date

Return date

Fine words

Remark

1

20081237

3007071

2010/09/19

2010/09/20

 

 

2

20071235

1005063

2010/10/20

2011/02/20

1

 

3

20071235

2001232

2011/09/01

 

 

 

4

20061234

1005063

2011/9/20

 

 

 

5

20051001

3007071

2011/9/10

 

 

 

6

20071235

1005050

2011/10/20

2012/02/20

1

 

Fine classification (CLC fine, fine name, penalties)

Fine words

Fine name

fine

1

extension

10

2

damage

20

3

Lose

50

Reservation (reservation serial number, library card number, ISBN, appointment)

Reservation serial number

Library card number

ISBN

Appointment

1

20081237

9787508040110

2011/09/11

(1) a table of contents for each of the graphic is inserted:

Such as editing "Book Category" list: First, right-click on the table to select "Edit data", as shown below:

 

In the edited data to the window, as follows:

 

Then click the green tick, green lock button and click commit, then submitted successfully

 

Insertion of the remaining data in the tables are as follows:

bibliography:

 

books:

 

reader:

 

Lending:

 

Fine Category:

 

reservation:

 

(2) SQL insert statement:

/ * Book Category * /

Books insert into classified values ​​( '100', 'literature');

insert into book classification values ​​( '200', 'technology');

insert into book classification values ​​( '300', 'philosophy');

/ * Bibliography * /

insert into books (ISBN, title, author, publishing units, unit price, books DOI) values ​​(, 'Introduction to Database Systems' 7040195836', 'Wang Shan', 'Higher Education Press', 39.00,' 200 ') ;

insert into books (ISBN, title, author, publishing units, unit price, books DOI) values ​​( '9787508040110', 'Dream of Red Mansions', 'Cao Xueqin', 'People's Publishing House', 20.00, '100');

insert into 书目(ISBN,书名,作者,出版单位,单价,图书分类号) values ('9787506336239','红楼梦','曹雪芹','作家出版社',34.30,'100');

insert into 书目(ISBN,书名,作者,出版单位,单价,图书分类号) values ('9787010073750','心学之路','张立文','人民出版社',33.80,'300');

/*图书*/

insert into 图书(图书编号,ISBN,是否借出) values('2001231','7040195836','否');

insert into 图书(图书编号,ISBN,是否借出) values('2001232','7040195836','是');

insert into 图书(图书编号,ISBN,是否借出) values('1005050','9787506336239','否');

insert into 图书(图书编号,ISBN,是否借出) values('1005063','9787508040110','是');

insert into 图书(图书编号,ISBN,是否借出) values('3007071','9787010073750','是');

/*读者*/

insert into 读者 values('20051001','王菲','四川绵阳西科大计算机学院','女','','','');

insert into 读者 values('20062001','张江','四川绵阳中心医院','男','','','');

insert into 读者 values('20061234','郭敬明','四川江油305','男','','','');

insert into 读者 values('20071235','李晓明','四川成都工商银行','男','','','');

insert into 读者 values('20081237','赵鑫','四川广元广元中学','女','','','');

/*罚款分类*/

insert into 罚款分类(罚款分类号,罚款名称,罚金) values(1,'延期',10);

insert into 罚款分类(罚款分类号,罚款名称,罚金) values(2,'损坏',20);

insert into 罚款分类(罚款分类号,罚款名称,罚金) values(3,'丢失',50);

/*借阅*/

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期,归还日期) values(1,'20081237','3007071',to_date('2010/09/19','yyyy/mm/dd'),to_date('2019/09/20','yyyy/mm/dd'));

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期,归还日期,罚款分类号,备注) values(2,'20071235','1005063',to_date('2010/10/20','yyyy/mm/dd'),to_date('2011/02/20','yyyy/mm/dd'),1,'');

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期) values(3,'20071235','2001232',to_date('2011/09/01','yyyy/mm/dd'));

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期) values(4,'20061234','1005063',to_date('2011/9/20','yyyy/mm/dd'));

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期) values(5,'20051001','3007071',to_date('2011/9/10','yyyy/mm/dd'));

insert into 借阅(借阅流水号,借书证号,图书编号,借书日期,归还日期,罚款分类号,备注) values(6,'20071235','1005050',to_date('2011/10/20','yyyy/mm/dd'),to_date('2012/02/20','yyyy/mm/dd'),1,'');

/*预约*/

insert into 预约(预约流水号,借书证号,ISBN,预约时间) values(1,'20081237','9787508040110',to_date('2011/09/11','yyyy/mm/dd'));

 

另外,对于plsqldev时间格式的设定如下:

 

8 设置日期型格式

  1. 使用SQL语句练习表的创建、删除、修改操作。

新建一个“实验”表,进行表的创建、删除、修改的操作:

创建表:

create table 实验(

实验编号   varchar2(5) primary key,

实验名称   varchar2(30) not null

);

select * from 实验;

 

修改:

alter table 实验

modify 实验名称 varchar2(40);

select * from 实验;

(此处“实验名称”变量类型变为varchar2(40))

alter table 实验

add 实验难度 varchar2(2);

select * from 实验;

 

删除:

alter table 实验

drop column 实验名称;

 

select * from 实验;

drop table 实验;

(此处将表进行了删除)

  1. 使用SQL语句练习表中数据的增加、删除、修改操作。

以上题所建实验(实验编号(primary key),实验名称(not null),实验难度)表进行操作。

create table 实验(

实验编号   varchar2(5) primary key,

实验名称   varchar2(30) not null,

实验难度   varchar2(2)

);

数据插入:

insert into 实验 values('19001','建立数据库','中');

insert into 实验(实验名称,实验编号) values('删库跑路','19002');

结果查看:

 

数据修改:

update 实验 set 实验编号 = '19003'

where 实验名称 = '删库跑路';

 

数据删除:

delete from 实验

where 实验名称 = '建立数据库';

 

另外,在本实验中之过程中也有许多对于数据表模式、数据表数据内容的新增、更改、查询和删除操作,进行了大量的练习。

  1. 试根据下面的完整性约束要求,用SQL对上面已经建立好的数据库表进行完整性约束定义。

读者关系中属性  联系电话  取值为11位数字

                身份证编号  取值为18位,并且满足身份证编号规则

图书关系中属性 是否借出  取值为:‘是’或‘否’

借阅关系中属性 借书日期  取值不为空

   完整性约束如下:

读者关系中:

电话号码约束:使第一位为1其余10位为数字。

check (regexp_like(联系电话,'^1[0-9]{10}$'))

         身份证约束:(第一个约束条件使身份证第1位不为0,第7到10位使身份证信息中的出生年份为1900到2099,第11到12位组合为月份01到12月份,且分别分出了31和30天的月份,再使2月份的天数为29天,最后一位约定可以为x和X;第二个约束条件使出生年份不超过2019年)

check (regexp_like(idc,'^[1-9]\d{5}(19|20)\d{2}((01|03|05|07|08|10|12)(0[1-9]|[1-2]\d|30|31)|(04|06|09|11)(0[1-9]|[1-2]\d|30)|02(0[1-9]|[1-2]\d))\d{3}(\d|x|X)$')

and regexp_like(idc,'^\d{6}((19\d{10})|(20(0|1)\d{9}))$'))

 

图书关系中:

    check (是否借出 = '是' or 是否借出 = '否')

借阅关系中:

    借书日期   date not null

实验心得与体会

本次实验是第一次实验课,在实验之前我们需要准备好软件平台,Oracle database的安装需要顾及到相应支持的软件,如.Net Framework 3.5,以及相应注册表的修改(使数据库兼容在Windows10上),再按照自己的需求进行软件的安装。在软件使用的过程中,我们至少需要简单了解相关服务项控制的是什么,才能更加方便的使用,为了创建数据库以及使用SQL语句的便捷性,和与实验室环境搭配,我们也使用的pl/sql development软件,用图形界面的方法方便我们对数据库的相关操作。

实验中图形化界面的使用弄懂了之后,编辑起来是很快,但是总会有一些报错,由于宏观操作数据,并不能很直观的知道到底是哪里出了问题,在之后的SQL语句创建数据库创建表的过程中,相当于重复着之前的行为,这时候再微观的构建数据库中便能更加直观的发现自己之前的错误,加深了自己的印象,自己也发现有没有理解透彻的知识点,回头翻书再仔细咀嚼一番,掌握的也更扎实了。

在数据库构建的时候,主键和外键的设置在我看来显得尤为重要,再加上完整性约束,三者在数据库健壮性中显得格外突出。我在实验中便经过了很多相关的坎,从未设置约束和外键,到完善约束条件,其中感悟心得挺多的:当你数据插入报错时,有可能是违反唯一性原则,反复插入了相同主键的数据;有可能是插入的数据外键指向的主键指定的表中找不到,不存在或者之前插入的值并没有commit。

这次构建数据库发生了许多低级的错误,给我的警示是,做事要仔细小心,不要冒失冒进,一味的求快可能效率会更低,踏踏实实走好每一步才行。

 

Guess you like

Origin www.cnblogs.com/swust-rjgc-1705-monitor/p/11697681.html