1:数据:描述事物的符号记录2:数据库是长期存储在计算机内,有组织可共享的大量数据的集合。
3:数据库管理系统维语用户和操作系统之间的一层数据管理软件,具有,数据定义,数据组织管理,数据操纵,数据库事务管理和运行管理,数据库建立和维护。
4:数据库系统:计算机系统引入数据库后的系统,简称数据库。
5:数据管理技术3阶段:人工管理阶段:数据不保存,应用程序管理数据,数据不共享,数据不具有独立性。
文件管理阶段:数据可以长期保存,文件系统管理数据,数据共享性差冗余大,数据独立性差。
数据库系统阶段:数据结构化,数据共享性好,冗余低,易扩充,独立性高。
6:数据模型分为:第一类:概念模型。
第二类是逻辑模型和物理模型,逻辑模型有(层次模型,网状模型,关系模型,面向对象模型,对象关系模型),物理模型:对数据最低层的抽象,描述数据库在系统内部的表示方式和存取方式。
从现实世界到概念模型的转换是由数据库设计人员完成,从概念模型到逻辑模型转换由数据库设计人员和工具完成,逻辑模型到物理模型就由DBMS完成。
7:数据模型由:数据结构(描述数据库对象和对象之间的关系),数据操作(对数据库中各对象的操作的集合),完整性约束(数据和其联系所具有的制约)三部分组成。
9:层次模型:简单清晰,查询效率高,良好的完整性支持,但是和现实世界不符,查询子女必须通过双亲。
网状模型:更直接的表达现实世界,存取效率高,但是结构复杂。
关系模型:简历在严格的数学模型上。
概念单一,简单易懂,存取路径对用户透明,高独立性,保密性,但是查询效率不高。
10:数据库三级模式结构:外模式,模式,内模式,外模式有多个,就是视图的意思,模式就是数据的逻辑结构,内模式就是物理结构。
11:三级结构有两层映像:外模式/模式映像:修改此映像保证外模式不变,保证逻辑路理性,模式/内模式映像,修改此映像保证模式不变,保证物理独立性。
12:数据库系统由数据库,数据库管理系统,应用系统和数据库管理员构成。
13:关系数据库:候选码:某一列的值能唯一标识一个元组。
主码:候选码之一。
候选码们的属性称为主属性,14:实体完整性:主码不为空。
参照完整性:关系的外码一定为其他关系的主码,或者外码全部为空。
用户定义完整性:比如XX不能为空,XX只能取指定值。
15:SQL 结构化查询语言16:查询:select。
定义:create,drop,alter。
操纵:insert,update,delete。
控制:grant,revoke。
17:为用户wang创建一个数据库,Create schema ST authorization wang;18:删除数据库Drop schema ST cascade/restrictCascade 把表都删了。
Restrict 如果下属有表,就拒绝删除19:创建表Create table student.course( cno char(4) primary key,Foreign key cpno references course(cno) )Create table student.course( sno char(9),Cno char(4),Primary key (sno,cno),)20:在student表中增加一列,入学时间。
Alter table student add entrance char(20); 21:把student表中的的年龄改为整形Alter table student alter column sage int; 22:在student增加课程名唯一的约束条件Alter table course add unique(cname);23:删除表Drop table student restrict/cascade24:建立索引Create unique index scon on sc(sno ASC,cno DESC) Unique 表明每一个索引值对应唯一数据记录25:删除索引Drop index scon26:查询Select sno,sname from student27:表达式查询Select sname,2004-sage from student;28:赋值查询Select sname,‘A’, lower(sdept) from student29:消除查询结果中的重复行Select distinct sno from sc;30:whereSelect sname from student where sdept=’CS’31:大小Select sname from student where sage<2032:介于Select sname from student where sage between 20 and 23; Select sname from student where sage not between 20 and23;33:在Select sname from student where sdept in( ‘CS’,’MA’,’IS’)Select sname from student where sdept not in( ‘CS’,’MA’,’IS’)34:字符匹配Select sname from student where sname like ‘刘%’Select sname from student where sname like ‘刘__’35:转义字符Select cno from course where cname like ‘DB\_Design’escape ‘\’36:空Select sno from SC where grade is null (不能用=) 37:排序Select sno,grade from sc where cno=’3’ order by grade desc38:数学函数Select count(*) from studentSelect avg(Grade) from sc where cno=’1’39:group bySelect cno,count(sno) from sc group by cno40:分组时的where要用数学函数的值作为判断条件的时候Select sno from sc group by sno having count(*)>3 41:等值连接Select student.*,sc.* From student,sc Where student.sno=sc.sno类似双重for循环,首先拿student.sno中的第一个依次和sc.sno中的比,只要相同的,就放进来,一直比完,如果sc.sno中有3项,那么放进结果表的就有3项。
这3项对应同一个student.sno。
42:自身连接Select o,second.cpnoFrom course first,course secondWhere first.cpno=o43:左外连接Select student.sno,sname,ssex,sage,sdept,cno.grade From student left out join sc on (student.sno=sc.sno) 就是显示出student所有的行,即便行不等于sc.sno44:复合条件连接Select student.sno,sname,cname,gradeFrom student,sc,courseWhere student.sno=sc.sno and o=o45:嵌套查询Select sname from student where sno in(select sno from sc where cno=’2’)46:ANY ALLSelect sname ,sage from student where sage <any (select sage from student where sdept=’CS’)And sdept<>’CS’ANY是某一个,这个是找出其他专业中比计科专业某一个学生年龄小的,是拿计算机专业中最大的年龄来比。
如果是ALL,就是比计算机专业中任何一个学生都小的,是拿计算机专业中最小的来比47:existsSelect sname from student where exists(select * from sc where sno=student.sno and cno=’1’) 首先在student中取一个元组,然后取出这元组的sno,和SC依依对比过去,得出结果集,再满足cno=’1’的条件,如果都满足了。
返回值为1,加入结果集。
48:集合 Union intersect exceptSelect * from student where sdept=’cs’UnionSelect * from student where sage <=1949:插入数据Insert into sc(sno,cno) values(‘200215128’,’1’) Insert into sc values(‘200215128’,’1’,NULL)不能不写50:求。
并存入数据库Insert into dept_age(sdept,avg_age)(dept_age表要先创建)Select sdept,avg(sage) from student group by sdept 51:ubdateUpdate studentSet sage=22Where sno=’200215121’52:删除数据Delete from student where sno=’200215128’53:创建视图Create view is_student AS select sno,sname,sage From student where sdept=’IS’With check option(以后视图修改增加数据的时候,都会判断where条件) Create view S_G(sno,Gavg) AsSelect sno,avg(grade) from sc group by sno;54:删除视图Drop view IS cascade55:对视图的更新最终还是要转换为对表的更新56:有些视图不能更新,比如视图有一项是各科平均成绩,这项不能映射回基本表,就不能更新。
57:视图的作用:简化用户操作,用户多角度看待同一数据,提供逻辑独立性,提供数据安全保护。
58:授权Grant all privileges on table student to public Grant update(sno),select on table student to U459:收回授权Revoke update(sno) on table student from U460:创建用户Create user U1 dba/resource/connect默认 connect 只能登陆数据库Resource 可以创建表和视图,Dba 可以创建新用户,模式、61:checkCreate table student Sno char(9) primary key, Sname char(9) not nullSsex char(2) check(ssex in(‘男’,‘女’))Sage smallint. Sdept char(20));62:函数依赖:一个x就可以确定一个y,一对一。