SQLServer数据库新手学习总结(前三)

2018-12-27  本文已影响0人  imtcf

经过一段时间的学习,也对数据库有了一些认识。

数据库基本是由表,关系,操作组成;对于初学者首先要学的:

1.数据库是如何存储数据的表,约束,触发器

2.数据库是如何操作数据的insert,update,delete T-sql 函数 存储过程 触发器

3.数据库是如何显示数据的select

1.SQL基础

SQL Server2000安装、配置,服务器启动、停止,企业管理器、查询分析器

第一代数据库--网状数据库和层次数据库;第二代数据库--关系数据库

数据库(DB);数据库管理系统(DBMS);数据库系统(DBS)

SQL Server 2000 提供了不同版本:企业版、标准版、个人版、开发版

SQL Server中的数据类型:整数:int,smallint,tinyint,bigint;浮点数:real,float,decimal;二进制:binary,varbinary;逻辑:bit;字符:char,nchar,varchar,nvarchar;文本和图形:text,ntext,image;日期和时间:datetime,smalldatetime;货币:money,smallmoney

数据库的创建和删除;数据库表的创建、修改和删除

数据完整性:实体完整性:Primary Key,Unique Key,Unique Index,Identity Column;域完整性:Default,Check,Foreign Key,Data type,Rule;参照完整性:Foreign Key,Check,Triggers,Procedure;用户定义完整性:Rule,Triggers,Procedure;Create Table中得全部列级和表级约束

SQL Server中有5种约束:主键约束(Primary Key Constraint)、默认约束(Default Constraint)、检查约束(Check Constraint)、唯一性约束(Unique Constraint)、外键约束(Foreign Key Constraint).

关系图

数据库设计的步骤:需求分析、概念结构设计、逻辑结构设计、数据库物理设计、数据库实施、数据库运行和维护

两个实体之间的联系:一对一(1:1)、一对多(1:n)、多对多(m:n)

实体关系模型 -- E-R图

数据库规范化:将数据库的结构精简为最简单的形式;从表中删除冗余列;标识所有依赖于其他数据库的数据。

数据库三范式:第一范式就是无重复的列;第二范式就是非主属性非部分依赖于主关键字;第三范式就是属性不依赖于其他非主属性

2.SQL语句

SQL全称是“结构化查询语言(Structured Query Language)”

SQL的4个部分:

数据定义语言DDL(Data Definition Language)用来定义数据的结构:create、alter、drop。

数据控制语言DCL(Data Control Language)用来控制数据库组件的存取许可、存取权限等得命令:grant、revoke。

数据操纵语言DML(Data Manipulation Language)用来操纵数据库中得数据的命令:insert、update、delete。

数据查询语言DQL(Data Query Language)用来查询数据库中得数据的命令:select。

SQL中得运算符:算术运算符、位运算符、比较运算符、逻辑运算符、通配运算符、字符串连接符、赋值运算符

3.查询

简单查询,使用TOP子句

查询结果排序order by

带条件的查询where,使用算术表达式,使用逻辑表达式,使用between关键字,使用in关键字,

模糊查询like

在查询中使用聚合函数:sum(x),avg(x),min(x),max(x),count(x),count(*)

使用分组查询group by,having子句

distinct关键字

列别名

select top 6 * from sales order by qty desc

select au_id,au_fname,au_lname from authors where state in('ks','ca','mi')

select au_fname,au_lname,phone from authors where au_id like '72[234]-%'

select type,sum(price),avg(price),count(*) from titles group by type having type in('business','psycheology')

http://imtcf.com

简单子查询:嵌套子查询、相关子查询;子查询的select语句中不能使用order by子句,roder by子句只能对最终查询结果排序。

嵌套子查询:执行过程,先执行子查询,子查询得到的结果不被显示,而是传给外层查询,作为外层查询的条件,然后执行外层查询,并显示结果。

嵌套子查询的执行不依赖于外层查询,子查询只执行一次。

带有比较运算符的子查询,带有in和not in的子查询,带有any或all的子查询

相关子查询:子查询为外层查询的每一行执行一次,外层查询将子查询引用的列的值传给了子查询。

相关子查询的执行依赖于外层查询,子查询需要重复的执行。

带有exists和not exists的相关子查询。

多表联接查询:内联接(inner join)、外联接((left、right、full)outer join)、自联接(self join)和交叉联接(cross join)

在查询上创建新表:select into语句首先创建一个新表,然后用查询的结果填充新表。

表别名

select coursename from course where courseid in(select distinct courseid from grade where grade>10)

select studname from student where sudbirthday > any (select studbirthday from student where class = '信息系') and class<>'信息系'

select studname from student where exists (select * from grade where studid = student.studid and courseid = '01')

select stud1.* from student as stud1 join student as stud2 on stud2.studname = 'mm' and stud1.studsex = stud2.studsex

select * into girls from student where studsex='m'

https://detail.1688.com/offer/587609877310.html?spm=a2615.2177701.autotrace-fullscreenImg.2.28d84f08zvNO0s

上一篇下一篇

猜你喜欢

热点阅读