数据库教学课堂笔记0416

更新时间:2023-11-06 23:02:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

数据库完整性: ? 实体完整性:

码非空==》主属性非空

NULL空值:不确定的值状态 NULL 与 ‘’/ ‘ ’ NULL 与 0

Dormno= Dormno=’NULL’ Dormno=’’ Dormno=‘ ’ Dormno is NULL

isNULL() //setNull() 下学期的补考名单:

? 参照完整性:

? 用户自定义完整性: SEX char(2) check(sex=’男’ or sex=’女’) Sage int check(sage>=1 and sage<=150)

==>最终的目的:保证数据库中数据的正确性

查询的结果是精确=》条件一定是准确

讨论:学生和宿舍的关系

1、 查询所有学生和宿舍的住宿可能性 2、 查询住宿学生的住宿情况 3、 查询所有学生的住宿情况

4、 查询所有宿舍的学生住宿情况 5、 查询所有学生和宿舍的住宿情况

实质:连接操作,实现应用语义的扩展 ? 任意连接:笛卡尔积,无条件连接 select * from student,dorm

? 条件连接:添加条件=》数据有效 ? 等值条件:语义相关性=》等值条件 缺点:片面强调等值关系的重要性,忽略了非等值的数据 缺点:1、2

select * from student,dorm where student.dormno=dorm.dormno

select* from student inner join dorm on student.dormno=dorm.dormno

? 自然连接:没有重复列 select sno,sname,sex,sage,dno,student.dormno,tele from student,dorm

where student.dormno=dorm.dormno

? 外连接:非等值条件的记录和“万能空值行”匹配+关联记录=》记录全集 ? 左外连接: select * from student,dorm

where student.dormno*=dorm.dormno

select* from student left outer join dorm on student.dormno=dorm.dormno

? 右外连接:

? 全连接:具有应用语义相关的有效数据集,实现“完全/所有” select * from student,dorm

where student.dormno*=dorm.dormno union

select * from student,dorm

where student.dormno=*dorm.dormno

select* from student full join dorm on

student.dormno=dorm.dormno

? 自身连接:查询与“原野”同一个系的学生信息 select s1.sname,s1.dno,s2.dno,s2.sname from student s1 ,student s2 where s1.dno=s2.dno and s1.sname='原野' and s2.sname!='原野'

select * from student

where dno=(select dno from student where sname='原野')

学习是要有深度的,只有有深度的学习才可以用!!!

除:实现“至少”语义 实现步骤

1、 对R、S:划分X、Y、Z

2、 对R(X)进行投影:得到x={。。。} 3、 在R上,找Yx的象集:

4、 在S上,对Y属性组投影:得到Πy 5、 进行集合的比较:包容关系 6、 如果包容:得到关系商:{x}

SQL:

结构化:模块化 国际标准 数据环境: =》见名知义

Select * from student where sno=’990101’ ==>C语言程序描述:循环遍历下有条件查询实现 关系: 1、 模式-表 2、 表: 数据类型

TINY INT 0-255

列级、表级约束:问题??? 3、

? 索引:难以理解,但很重要的

? 实质:就是数据的顺序/有序=》数据访问效率

数据遍历:从头到尾地走一遍,性能很差,速度很慢

? 数据顺序:

? 物理顺序:记录号顺序,数据在录入时形成的实际存储顺序,只有一个

? 逻辑顺序:记录顺序的某一种操作访问需求是多样的=》添加多个逻辑顺序号,需要额外代价:先建立索引文件

? 用户操作顺序:无论数据库是什么顺序(物理/逻辑顺序),输出的数据顺序一定要满足用户所要的操作要求的顺序。

? 用户操作顺序的实现:

? 排序:改变物理顺序,实现用户操作,代价大=》聚簇索引

? 索引:给定一个相应的逻辑顺序,实现用户操作=》唯一/普通索引 ? 实质:索引对照表 索引分类: ? 普通索引 ? 唯一索引 ? 聚簇索引

SQL查询

Select <目标列表达式:投影结果>

From <数据源:表/视图/临时表,单表/多表操作>

Where<连接条件/记录筛选条件>

Group by<分组关键字> having<分组条件>

Order by <最终结果输出序:排序关键字> UNION <集合并>

? Select <目标列表达式:投影结果>

十种形式:*/常量:字符串、数值/指定列/表达式(计算值)/别名/唯一值/前N个/前N%/ALL

select * from student 所有默认目标列:顺序

select classno,sno,sname

from student 指定列:显示顺序 select sno,sname ,2011-sage

from student 字段表达式:求值 select sno,sname ,year(getdate())-sage from student 函数表达式:

select sno,sname ,year(date())-sage 出生年月 from student

select sno,sname ,year(date())-sage as 出生年月 from student 列别名:添加一个列标题,支持“西文字段、中文显示”

select sno 学号,sname 姓名,\出生年份:\,year(date())-sage as 出生年月 from student 字符串常量:提示信息

select 3+5,classno from student数值常量 select distinct classno from student唯一值显示

select top 3 * from student order by grade desc 取前N个

select all * from student order by grade desc所有:默认 select top 10 percent *

from student order by grade desc取前N%:

? From <数据源:表/视图/临时表,单表/多表操作>

单表/多表操作判定:

用户要求实现的查询操作的结果和条件等,如果在一个表,为单表操作。不在一个表,则为多表操作

select sno,sname,dno from student where dno='1'

select * from student ,department where student.dno=department.dno and dname='数学系'

select * from (select * from student where dno='1') s

where s.sex='男' ? 查询班主任“XYZ”所带的所有学生信息。 select *

from student,class

where class.classno=student.classno and

teacher='XYZ'

select *

from student inner join class

on class.classno=student.classno where teacher='XYZ' 连接条件/关联条件

class.classno=student.classno 主键 外键 class.classno*=student.classno 主键 外键

参照完整性:外键-主键的对应关系

? 有值:外键的值一定是一个主键中的值 ? 无值:可以为空值 NULL

? From <数据源:表/视图,单表/多表操作> 单表/多表操作:

用户要求实现的查询操作的结果和条件等,如果在一个表,为单表操作。不在一个表,则为多表操作

select classno,sno,sname from student 无连接条件

? 查询班主任“XYZ”所带的所有学生信息。

连接条件:形式多

select teacher,sex,sno,sname,student.classno from student

inner join class

on class.classno=student.classno where sex='男'

连接分类:实体之间关系=》数据关系 实例:学生(12)-宿舍(5)的关系 学生:有宿舍、未分配宿舍

宿舍:有学生的宿舍、无学生宿舍

+ 宿舍的性别状态:男生|女生

宿舍的人数:一个宿舍不超过5人

1、 查询所有宿舍和所有学生的住宿可能

性:12*5=60

==〉笛卡尔积/任意连接:构建一个应用问题的解空间:无效解

2、 查询住宿学生的住宿情况:

非条件/条件连接/等值条件连接/自然连接 ==〉实现“相关”语义:片面强调了等值条件的重要性,忽略了非等值的数据记录 产生了两个缺点:冗余列 ,丢失了“所有/完全”概念

3、 查询所有学生的住宿情况 外连接:(左右)为了弥补等值连接的缺点,实现“所有/完全”语义:给不符合等值条件的记录,用“万能空值行”去匹配,实现“所有/完全”概念

4、 查询所有宿舍的学生情况

5、查询所有学生和所有宿舍的情况:

全连接:左、右外连接的并集=》构建一个符合应用语义的多表关联的有效解空间集。

=》连接/多表(关联)操作: ? 笛卡尔积/任意连接+

? 条件连接:等值条件连接/自然连接 ? 外连接:左、右 ? 全连接: ? 自身连接

查询与“原野”同一系的学生。 select * from student,dorm

where student.dormno=dorm.dormno

12*5=60

select * from student,dorm 笛卡尔积:构建问题的解空间

任意连接:无条件限制,构建一个问题的解空间

select * from student,dorm

where student.dormno=dorm.dormno select * from student inner Join dorm on student.dormno=dorm.dormno

条件连接:等值连接/vFP的内连接,具备关联语义

缺陷:片面地强调等值条件的重要性,忽略了非等值的记录的关系

5、 查询所有学生的住宿情况

select * from student left outer join dorm on dorm.dormno=student.dormno 外连接:实现“所有”、“完全”语义,

分为:左外连接、右外连接 6、 查询所有宿舍的学生情况

select * from student right outer join dorm on dorm.dormno=student.dormno 或

select * from student left outer join dorm on dorm.dormno=student.dormno

************************************* select * from student left outer join dorm on dorm.dormno=student.dormno

====select * from dorm left outer join student on dorm.dormno=student.dormno

==》 。。。。

select * from student right outer join dorm on dorm.dormno=student.dormno

*************************************

select dorm.*,student.*

from student right outer join dorm on student.dormno=dorm.dormno

7、 查询所有学生和所有宿舍的情况:

全连接:等值+左连接+右连接=》构建一个应用问题的有效解空间 select dorm.*,student.* from student full join dorm

on student.dormno=dorm.dormno

=>宿舍分配问题:

给没有住宿的学生分配可以住宿的宿舍=》给出一个合理的住宿方案。

select sno,sname,d.dormno from

(select sno,sname,sex from student where dormno is null) s, (select dormno,sex from student where dormno is not null group by dormno,sex having count(dormno)<5) d where s.sex=d.sex union

select sno,sname,d.dormno from

(select sno,sname,sex from student where dormno is null) s,

(select dormno from dorm

where dormno not in(select dormno from student where dormno is not null)) d

{问题:查询与“原野”同一个系的学生} select *from student s1,student s2 where s2.dno=s1.dno and s1.sname='原野' and s2.sname!=s1.sname 与

select *from student s1,student s2 where s1.sname='原野' and s2.dno=s1.dno

and s2.sname!=s1.sname 区别,理由何在???

? Where<连接条件/记录筛选条件> 查询:精确=》唯一性=》准确条件 条件表达式:逻辑型 ? 比较运算:!=,<>,#,=/==

select * from student where sno='99001' 唯一性条件=》精确唯一结果

select * from student where classno='9901'多值

条件表达式的对应性:字段与给定值之间的数据类型的一致性

select * from student where sage='21' 数值INT 字符 select * from student where sage!=21 select * from student where sage<>21 select * from student where sage#21

select * from student where not(sage=21) select * from student where !(sage=21) ? 逻辑运算:and,or,not 组合条件:多个条件 ? 集合运算:IN

select * from student where classno='9901'

or classno='9902' or classno='9903' ==》

select * from student

where classno in ('9901','9902','9903') 针对数据:离散的值,可枚举的值 ? 范围比较:between…and… select * from student

where sage>=18 and sage<=20 =>

select * from student

where sage between 18 and 20 ? 字符比较:

字符不等:对应字符不相同 字符相等:

? 精确匹配:对应字符相同,长度相同 ? 模糊匹配:对应字符相同 =/==:VFP提供

‘aaa’==’aaa’//‘aaa’=’aaa’ ‘aaa’==’a’//‘aaa’=’a’

?'aaa'=='aaa' T ?'aaa'='aaa' T ?'a'=='aaa' F ?'a'='aaa' F ?'aaa'=='a' F

?'aaa'='a' T (包容相等)

select * from student where sname like '张%' select * from student where sname='张%'

select * from student where sname='张原' select * from student where sname like '张原'

格式匹配:LIKE,模式识别 通配符:

? %:任意字符

? _:单个字符,西文单字符,中文单汉字

select * from student where sname='张扬' select * from student where sname like '张扬' select * from student where sname='张%' select * from student where sname like '张%'

select * from student where sname like ' 明%'

select * from student where ltrim(rtrim(sname)) like '明%' select * from student where ltrim(rtrim(sname)) like '_明%' select * from student where ltrim(rtrim(sname)) like '__明%'

所有以‘a’开头的姓名的学生信息 Where sname=’a’

Where sname like ‘a%’ Where sname like ‘a_’

select * from student where sname like 'a%' select * from student where sname like 'a_' select * from student where sname like 'a__' select * from student where sname like 'a___' select * from student where sname like 'a%' select * from student where sname like '%a%'

select * from student where sname like 'a%' select * from student where sname like 'a_' select * from student where sname like 'a__' select * from student where sname like 'a___' select * from student where sname like '%a%' select * from student where sname like '_a%' select * from student where sname like '__a%'

DB_DESIGN a_ABCD

select * from student

where sname like 'a\\_%' escape '\\' 转义符 西文字符:单字节,只占一个位 中文字符:双字节,占两个位

? 空值比较:

查询学生中没有在校住宿的学生信息 select * from student where dormno is null isNull()//SETNULL()

? Group by<分组关键字:聚集> having<分组条件> 前提:

数据库的记录认识:

? 个体属性特征:每一条记录的某些具体属性:实体

select sno,sname from student where sno='99001'

)

create table spj41 (sno char(2) , pno char(2) , jno char(2) ,

spjid char(6) not null unique, constraint PK_spj41 key(sno,pno,jno) )

create table spj42 (sno char(2) , pno char(2) , jno char(2) ,

spjid char(6) not null unique, primary key(sno,pno,jno) )

alter table spj41

drop constraint PK_spj41

primary

alter table spj42

drop constraint PK__spj42__300424B4

insert into spj3 values('s1','p1','j1') insert into spj3 values('s1','p1','j3')

select * from spj3

insert into spj4

values('s1','p1','j1','s1p1j1') insert into spj4

values('s1','p1','j3','s1p1j3') select * from spj4

? 实体完整性检查:只针对修改、插入操作

? 参照完整性:先建立被参照表的主码、才可以定义参照表的外码

? 定义:

? 违约处理:

? 从表添加记录,而主表没有相应的主记录、

? 从表修改记录,修改后而主表没有相应的主记录

? 主表删除主记录,从表如何处理 ? 主表修改主记录的主码,从表如何处理 ?

数据操作:不是一个简单的“增删改查”,而是在一个符合应用语义的数据环境的一致性操作。

数据库规范化设计:

SNO Sname SDEPT 99001 AAA 99001 AAA 99001 AAA CS CS CS MA MNAME 王=》张 王 王 李 CNAME DB ENG MATH ENG GRADE 85 79 77 99 99003 CCC 99003 DDD 01002 DDD MA MA ST 李 李 劳 MATH XSX 88

缺点:违反了“主题相关原则”、“一事一地” 错误:一个应用问题一般是不可能用一张数据表来设计实现的!!!

【数据库设计实质】==》实际上,是用一个符合应用语义的多表连接的数据环境来实现。

【数据操作】:不是一个简单的“增删改查”,而是在一个符合应用语义的数据环境的一致性操作。

? 范式 与 规范化 BC范式:

SPJ(S,P,J,(S,J)->P,(J,P)->S) 码:(S,J)\\(J,P) 非主属性:NULL

因为,不存在非主属性 所以,

SPJ属于2NF、3NF

讨论:决定因素包含码

1、 具体指明哪一个码?:包含某一个码 2、 包含所有的码?:不要求 因为,(S,J)\\(J,P)包含码 所以,SPJ属于BCNF S P J

4NF推导:

关系Teach(C,T ,B,(C,T,B)->U) 码:(C,T,B),全码 非主属性:NULL

显然:属于2NF、3NF 因为(C,T,B)->U

决定因素包含码:(C,T,B) 那么,属于BCNF

SQL:数据库数据处理 高级程序语言《==》SQL DBAS:数据库应用系统 前台 + 后台

? 群体属性特征:忽略个体,聚集后的数据特征

从这个角度上讲:“原野”不再是一个“人”、而变成一个数

select count(*) from student ==》分类统计:分类求和 ? 集函数:满足统计需求

select count(*),max(sage),min(sage) from student =》

COUNT( )

MAX( )//MIN( ) SUM( )

AVG( ):一般多用于数值字段、可比性字段

select * from student where sname='原野' select count(*),max(sage),min(sage) from student select sname,count(*)from student group by sex select sex,count(*)from student group by sex having sex='男'

select sex,count(*)from student where sex='男'

select count(distinct classno) from student select count(*) from student select sex,count(*) from student group by sex

select classno,count(*) from student

group by classno

select max(sage),min(grade) from student 循环遍历操作:高效

select classno,sum(grade) from student group by classno

select classno,avg(grade) from student group by classno

? 分组:按“分组关键字”相同为原则 分组条件:having

select dno,count(*) from student where dno='2'

select dno,count(*) from student group by dno having dno='2'

进行统计操作:两种方式

1、 先分组,再统计,最后选择=》having条

select dno,count(*) from student group by dno

select dno,count(*) from student group by dno having dno='2'

2、 先过滤/选择,再统计=》WHERE条件 select * from student where dno='2'

select count(*) from student where dno='2'

having条件 与 where条件的区别: ? 相同: ? 不同:

select dno,count(*) from student where dno='2'

==>select '2' DNO,COUNT(*) from student where DNO='2' select dno,count(*) from student group by dno having dno='2'

*********

查询院系人数超过3个人(>=3)班级信息 select dno,count(*) from student; group by dno having count(*)>=3 ==》

select dno,count(*) from student; group by dno where count(*)>=3

注意:集函数是不能用于WHERE条件子句

查询“1系”和“2系”的人数情况:总和//分类和

Select count(*) from student where dno='1' or dno='2'

Select dno,count(*) from student

group by dno having dno='1' or dno='2' *********************************** Order by <最终结果输出序:排序关键字> 难点:多字段、不同类型的字段排序=》优先级别

select * from student

order by sex,classno desc,grade asc

select * from student

where dno =(SELECT dno FROM STUDENT WHERE SNAME='原野' order by sno) order by sage

select * from (select * from student where dno ='1' order by sname) S

WHERE S.SEX='男' order by sage desc

? UNION <集合并>

前提:相同的字段个数、顺序,相同的数据类型

select * from student where classno='9901' union

select * from student where classno='9902'

? 嵌套查询:结构化思想:模块调用

SQL块:形式上语句块,实质上是数据区 select * from student

where dno=(select dno from student where sname='原野') select * from student s1

where exists(select * from student s2 where sname='原野' and s1.dno=s2.dno)

select *

from (select * from student where dno='1') s where s.sex='男'

查询与‘原野’同一系的学生。

? 不相关子查询:分步操作、由内向外、当

外查询执行时,内查询已经执行结束,时一个确定的值集合 查询一些学生: 1、‘原野’是哪一个系

2、与‘原野’的系号相同【同一系】的学生信息

? 相关子查询:由外向内、执行过程不同 查询什么

1、找学生,什么样的学生??

2、这样的学生:与“原野”同一个系的学生:判定条件

select * from student s1

where exists(select * from student s2 where sname='原野' and s1.dno=s2.dno)

ANY:碰见一个满足条件的记录就结束查询 ALL:所有记录满足条件

EXISTS:存在量词,不返回任何数据,只产生一个逻辑值。

适合针对“至少”语义或除操作

相反语义=》否定之否定=肯定

select * from student

where sno in( select sno from grade where cno='01')

select * from student s ,grade g where s.sno=g.sno and cno='01'

? 集合查询:集合操作 create view Vstu

as select sno 学号,sname,dno from student select * from student where sno='990101' select * from VSTU where 学号='990101' select sno,sname, dno from student where dno='1' union

select dno,sname, sno from student where dno='2'

数据库四大操作:增、删、改、查 ? 检索:查询

? 更新操作:增、删、改 增:插入=》尾部追加

SQL数据库中数据的顺序是无关紧要 ? 缺省列插入:插入数据值的顺序与数据表默认顺序相同 insert into dorm values('2606','8306')

insert into dorm values('8306','2606')

? 指定列插入:没有输入的字段为NULL

insert into dorm(dormno,tele) values('2707',NULL)

insert into dorm(dormno) values('2707')

? 不成功:违反了完整性

{^2009-09-25}:日期常量形式 create table dorm1

(dormno char(5) not NULL unique, tele char(7));

insert into dorm1

select * from dorm where dorm='2202'

? 修改:update <> Set <> Where <> ? 单记录

update class

set teacher='TTT'

where classno='9802' 唯一性条件 ? 批量记录

update student set grade=grade+10 where sex='男' update student set classno='9901',grade=grade-10 where sex='男'

update grade set score = 0

where '数据库原理'=(select cname from course where course.cno=grade.cno)

update grade set score = 0

where cno=(select cno from course where course.cname='数据库原理')

删除delete:逻辑删除,只加删除标记,物理删除+PACK Delete from Where ? 单记录

Delete from class

where classno='9802' 唯一性条件 ? 批量记录

Delete from student Where sex=’男’ ? 所有记录

Delete from student

数据库下正确性的理解: ? 正确=》语法/结果正确 ? 正确=》一致性正确

提示:更新操作不应该理解为简单的“单表操作”,=》在多表关联的数据库环境下的关联数据操作【语法正确+语义正确】

数据正确性操作的基本单位???

==》事务操作:要么操作、要么都不做 主从表的关联删除:

原则:先删从表、再删主表

数据库如何维护一致性的正确性??? ? 创建数据库:补充相应的完整性

delete from grade where sno='990102' delete from student where sno='990102'

select * from student where sno='990102'

select * from grade where sno='990102'

VIEW ******

CREATE VIEW vSTU(学生编号,学生姓名) AS

select sno,sname from student

CREATE VIEW vSTU1 AS

select sno 学生编号,sname as 学生姓名 from student

select * from Vstu1

CREATE VIEW vSTU2 AS

select * from student

select * from vstu2 ******

create view dno1 as

select dno,student.sno,sname,cno,score from grade ,student

where student.sno=grade.sno and dno='1'

create view dno1S as

select * from dno1 where sname like '张%'

create view dno1SC as

select * from dno1S where cno='01'

drop view dno1S select * from dno1 select * from dno1S select * from dno1SC ******

create view G_stu(学号,平均成绩) as

select sno,avg(score) from grade group sno

select * from G_stu

by select * from grade 数据库重组、重构 create table sX

(sno char (6) not NULL unique, sname char (8) not NULL , sex char (2) )

insert into sX

values ('990101','原野','男'); insert into sX

values ('990102','张原','男'); insert into sX

values ('990103','李军','男'); insert into sX

values ('990104','汪远','男'); insert into sX

values ('990105','齐欣','男'); insert into sX

values ('990201','王大明','男'); insert into sX

values ('990202','徐东','男'); insert into sX

values ('990301','张扬','女'); insert into sX

values ('990302','于洋','女'); insert into sX

values ('990303','姚志旬','男'); insert into sX

values ('990401','高明镜','男'); insert into sX

values ('990402',' 明天','男');

create table sY

(sno char (6) not NULL unique, sage int,

dno char(4) , dormno char (5) )

insert into sY

values ('990101',21,'1','2101'); insert into sY

values ('990102',21,'1','2101'); insert into sY

values ('990103',20,'1','2101');

insert into sY

values ('990104',20,'1','2101'); insert into sY

values ('990105',20,'1','2101'); insert into sY

values ('990201',19,'2','2202'); insert into sY

values ('990202',19,'2','2202'); insert into sY

values ('990301',21,'1','2303'); insert into sY

values ('990302',20,'3','2303'); insert into sY

values ('990303',19,'4','2404'); insert into sY

values ('990401',19,'4',null); insert into sY

values ('990402',21,'4','2404'); *****

DROP TABLE student SELECT * FROM Student

create view student as select

SX.SNO,SNAME,SEX,SAGE,DNO,DORMNO

from SX,SY where sx.sno=sy.sno

SELECT * FROM SX

SELECT * FROM Sy

用户管理:以SQLSERVER为例 1、 NOPOWER:合法、但无权限 2、 SUSER:管理员角色,兼具系统和用户

的所有权限

3、 MUSER:一般数据库用户,获得

PUBLIC身份:区别对待 先别定义: SELECT: 空 DELETE:绿勾 update:红叉 *****

grant select on student to Muser

revoke INSERT on STUDenT from Muser grant delete on student to Muser *****

select * from student

delete from student where sno='990101'

*****

revoke select on student from Muser

grant delete on student to Muser *****

select * from student insert into student

values ('880101','AAA','男',21,'1','2101');

delete from student where sno='990101'

update student set sex='女' where sno='990102'

用户权限:

1、 不是技术问题、是政策问题

2、 涉及对象:授权方、被授权方、数据对

象、操作权限类型:=》授权金字塔、级联、权限组/角色

3、 权限组/角色:简化授权

4、 数据库权限:操作权限、管理权限 5、 构造实例:授权一定验证 a) Nopower:无权、合法用户 b) Suser:系统角色、没有用户数据库授权 c) Muser:仅是数据库用户:待授权/剥夺权限用户

三态: 空/绿勾/红叉

grant insert on grade to pow2

grant delete on grade to pow2

revoke select on grade from pow2 *****

select * from grade

insert into grade

values('999999','09',99)

delete from grade where sno='990101' select * from grade where sno='990101'

DAC与MAC MAC: 读: 写:

? 视图授权:外模式的授权

? 系统管理用户 ? 一般操作用户

select student.sno 学号,sname 姓名,sage 性别,student.dno 系号,dname 系名,head 主任,grade.cno 课程号,cname 课程名,score 成绩

from student ,department,grade,course where student.dno=department.dno

and student.sno=grade.sno and grade.cno=course.cno 数据库完整性: 两类:表级\\列级

区分:组合主码只能用表级约束

? 实体完整性:主键、候选码:非空/唯一 ? 参照完整性:主/子表创建和删除顺序、违约处理

DEPT(DNO,DNAME) EMP(ENO,。。。,DNO) ?

问题研究: ? 是一个关系R 形式化:

R(sno 学号,sname 姓名,sage 性别,student.dno 系号,dname 系名,head 主任, cno 课程号,cname 课程名,score 成绩) ? 主码:

(SNO,CNO) ? 异常:

插入一个新的学生:新生+未选课

删除一个学生:一个系只有一个学生时

修改数据记录:一次=》多次

===》本质:数据冗余度“太”高

习惯=:一个表存放一个问题,它不是问题最优的实现。

基于“主题相关原则”:投影分解

【观点】数据时需要预处理的,因为采集于现场的数据时不一定的标准和严格

=》数据规范化的实质:讨论码和非主属性、决定因素之间的关系

多值依赖:

认识:是笛卡尔积? DBAS:数据库应用系统 前台 + 后台

ODBC/数据库连接接口

程序/界面/功能 数据库服务器 PB:C/S结构下程序的前端开发工具 PB开发四个层次

1、 WORKSPACE工作区 2、 APPLICATION应用 3、 WINDOWS窗体 4、 CONTROL控件

面向对象开发:属性和操作的封装体

? 属性:静态特征=》定制界面:绘制“样子”

? 操作:动态特征=》功能/动作:编写代码脚本、框架代码=》方法、函数、事件

完整性:属于结构定义范畴 ? 实体完整性

? 表级/列级约束: create table spj

(sno char(2) not null unique, pno char(2) not null unique, jno char(2) not null unique )

? 主码/候选码/唯一+非空

1、 一个表只能有一个primary key 2、 候选码有多个:not null unique

create table spj (sno char(2) , pno char(2) , jno char(2) , constraint PK_spj key(sno,pno,jno) )

create table spj3 (sno char(2) , pno char(2) , jno char(2) ,

spjid char(6) not null unique, constraint PK_spj2 key(sno,pno,jno) )

create table spj4

(sno char(2) primary key, pno char(2) primary key, jno char(2) primary key, spjid char(6),

primary

primary

本文来源:https://www.bwwdw.com/article/qwg2.html

Top