数据库基础知识整理1——增删改查

数据库:管理数据的地方。
数据库的发展阶段:层次型、网状型、关系型。
DB(Database) DBMS(数据库管理系统) DBS(数据库系统)

主流的数据库:SQLServer,Oracle(甲骨文),DB2(ibm),sybase,access,foxpro
SQL语言——国际化标准。Transaction-SQL,PL-SQL

管理类的书——DBA数据库管理专家。
开发类的书——开发人员——SQL语法

SQLServer数据库三个层次:
1.文件(.mdf,.ldf)。2.界面。3.服务。

体验版——不花钱。
企业版——花钱。
开发版——不花钱。

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

数据库:
三个层次:文件--服务--界面 (DBMS)
两种登录方式的设置:Windows身份登录;SqlServer身份登录。


如何设置SQLServer身份验证?
1.对象资源管理器右击--属性--安全性--SqlServer和Windows身份登录。
2.对象资源管理器--安全性--登录--sa--右击--属性--常规--设置密码
3.对象资源管理器--安全性--登录--sa--右击--属性--状态--授予,启用
重启数据库服务。

如何新建数据库?
……

.ldf——日志文件
.mdf——主数据文件
.ndf——次数据文件
一个数据库中,可以有多个日志文件,多个次数据文件,但只能有一个主数据文件。

如何新建表?
……

行次序无关,列次序无关。

SQL语句 DDL DML(增、删、改、查) DCL

insert into 表名(列名,列名,列名,...) values(值,值,值,....)
insert into 表名 values(值,值,值,值。。)

一、简单查询
select * from 表名
select 列名,列名,...from 表名    ——投影
等值与不等值查询
select * from 表名 where 列名=值    --等值查询
不等值查询
select * from 表名 where 列名 <>select * from 表名 where 列名 > 值    >=
select * from 表名 where 列名 < 值    <=

多条件查询 逻辑与(and),逻辑或(or)
select * from 表名 where 条件1 and 条件2 ...
select * from 表名 where 条件1 or 条件2 ...
如果在where筛选条件中,既出现and又出现or,则先运算and。除非使用小括号改变优
先级。

范围查询。
select * from Car where Price >=30 and Price<=50
select * from Car where Price between 30 and 50

select * from Car where Oil=7.4 or Oil=8.5 or Oil=9.4
select * from Car where Oil in(7.4,8.5,9.4)

模糊查询。 一般不用=,而是用like
%——任意多个任意字符
_——一个任意字符
select * from Car where Name like '宝马%'
宝马%——以宝马开头的
%宝马——以宝马结尾的
%宝马%——只要含有宝马这两个字就可以。

__宝马%——代表第三个字符以宝马开头的。

去重查询:
select distinct 列名 from car ——如果列中有重复值,则只查1个出来。

排序
select * from car order by price asc ——默认是升序 ascending descending
select * from car order by price desc
select * from Car order by Oil asc,Price desc ——Oil主排序,Price次排序

delete from car ——删除全部数据
delete from car where 条件    ——这里的条件是跟select的条件是一样的。

update 表名 set 列名=值,列名=值..... where 条件
update Car set Price = Price + price * 0.15 where Name like '宝马%'
update Car set Name='300C 3.5L 商用车',Oil='9' where Code='c012'

 

select top 数字 列 * from 表名
原文地址:https://www.cnblogs.com/viven/p/4323531.html