数据库管理系统(DBMS)是位于用户和操作系统之间的一层数据管理软件。
数据库系统(DBS)是由数据库、数据库管理系统、应用程序和数据库管理人员(DBA)组成的存储、管理、处理和维护数据的系统。
两层数据模型
逻辑模型(从软件管理角度组织数据)由数据结构、数据操作、数据的完整性约束三部分组成。
物理模型(从硬件存储角度组织数据)
概念模型
一对一联系
一对多联系
多对多联系
连接到服务器
新建查询 create database db_StuInfoMangement 执行!use db_StuInfoMangement
create table tb_Student
( Sno CHAR (10) PRIMARY KEY,
Sname CHAR(20) UNIQUE,
Ssex CHAR(2),
Sage SMALLINT,
Sdept CHAR(20)
);
建表成功!
数据库->db_StuInfoMangement->表->系统表->dbo.tb_Student;
增加一列数据 alter table tb_Student ADD Sphone CHAR(10) ;
dbo.tb_Student->右键编辑前两百行(自己输入数据)
select sname, sage from student where sdept = ‘ cs ‘
select sno, grade from sc where cno = ‘01‘
select sno, cno, grade from tb_student where grade between 70 and 80
select sname, sage from student where sdept = ‘cs‘ and ssex=‘男‘ and sage between 18 and 20
select * from sc where sno = ‘9512101‘
select max(grade) as max_grade from sc where cno = ‘01‘
select distinct cno from sc
select max(ssag) as 最大年龄, min(ssag) as 最小年龄 from student
*查询修了02号课程的所有学生的平均成绩、最高成绩和最低成绩。
select avg(grade) 平均成绩, max(grade) 最高成绩, min(grade) 最低成绩
from sc where cno = ‘02‘
select sdept,count(*) 学生人数 from student group by sdept
select cno 课程号, count(*) 修课人数, max(grade) 最高分 from sc group by cno
select sno, count(cno) 选课门数 from sc group by sno order by 选课门数
select sdept, count(distinct sc.sno), avg(grade)
from student , sc
where student.sno = sc.sno
group by sdept
select sno, sum(grade) 总成绩, avg(grade) 平均成绩, count() 选课门数
from sc
group by sno having count() > 2
select sno, sum(grade) 总成绩
from sc
group by sno having sum(grade) > 200
select sname, sdept
from Student , SC
where Student.Sno = SC.Sno and cno = ‘02‘
select sname, cno, grade
from student , sc
where Student.Sno = SC.Sno and grade > 80
order by grade desc
insert into student values(‘200215121‘,‘李勇‘,‘男‘,20,‘CS‘);
insert into student values(‘200215122‘,‘刘晨‘,‘女‘,19,‘CS‘);
insert into student values(‘200215123‘,‘王敏‘,‘女‘,18,‘MA‘);
insert into student values(‘200215125‘,‘张立‘,‘男‘,19,‘IS‘);
go
insert into course values(‘1‘, ‘数据库‘, NULL,4);
insert into course values(‘2‘, ‘数学‘, NULL,2);
insert into course values(‘3‘, ‘信息系统‘, NULL,4);
insert into course values(‘4‘, ‘操作系统‘, NULL,3);
insert into course values(‘5‘, ‘数据结构‘, NULL,4);
insert into course values(‘6‘, ‘数据处理‘, NULL, 2);
insert into course values(‘7‘, ‘PASCAL语言‘, NULL,4);
go
update Course set Cpno = ‘5‘ where Cno = ‘1‘;
update Course set Cpno = ‘1‘ where Cno = ‘3‘;
update Course set Cpno = ‘6‘ where Cno = ‘4‘;
update Course set Cpno = ‘7‘ where Cno = ‘5‘;
update Course set Cpno = ‘6‘ where Cno = ‘7‘;
/为表Course添加数据/
go
R - S 仍为n目关系,由属于R或不属于S的元组组成
R ∩ S 仍为n目关系,由属于R又属于S的元组组成
选择操作时在关系R中选择满足给定条件的诸元组,其表示形式为:
σf(R)={ t|t∈R∧F(t)=‘真’}
R?S={tr⌒ts |tr∈R∧ts∈S∧tr[B]=ts[B]}
θ为“=”时的连接称为等值连接,从关系R和S的笛卡尔积中选取属性组A和B之相等的元组
除法运算是二目运算
原文:https://www.cnblogs.com/Dr-STranger/p/12960884.html