第一章
1.2 数据库系统的特点
结构化
冗余小
共享性
独立性
由DBMS统一管理和控制
安全
完整
并发
恢复
1.3 数据库系统的结构
三个角度
用户视图
DBMS内部的系统结构
三级模式
概念模式
描述数据库全局数据逻辑结构,全体用户公共数据视图,给出了每个用户的局部数据描述
外模式
内模式
DBMS管理的角度
DBMS外部
系统应用
CS
BS
表示层
处理层
1.4 数据模型
物理层
逻辑层
层次模型
概念层
概念模型
表示方法
ER
关系模型 —— ER的数据库中的表示形式
一些概念
元组
外键/外部码
关系规范化的一些方法
第一范式
BCNF
1.5 数据库设计
概念
数据库设计的六个阶段
需求分析
概念结构设计
逻辑结构设计
物理结构设计
数据库实施
数据库运行与维护
概念结构设计
逻辑结构
转换规则: 巴拉巴拉巴拉巴拉这是一坨屎
物理设计
第二章 MySQL概述
2.1 MySql系统特性
2.2 安装和设置
2.3 服务的启动与关闭
services.msc
net start mysql
net stop mysql
2.5 MySql语言结构
structured Query Language
数据语言的组成
DDL defininition
CREATE
ALTER
DROP
DML
SELECT
INSERT
UPDATE
DELETE
DCL
GRANT
REVOKE
Sql语言要素
常量
变量
用户变量
系统变量
运算符
位运算
比较运算
逻辑运算
函数
数学函数
聚合函数
字符串函数
日期
加密
控制流程函数
格式化函数
类型转换函数
系统信息函数
第三章 数据库和表
3.1 数据库的创建和使用
CREATE DATABASE [IF NOT EXISTS] db_name
show databases
show create database db1
create database db2 character set GBK;
show character set;
collation:校验规则
alter database db2 character set utf8 collate utf8_general_ci
drop database (if exists) db2
use db1
选择
select database()
查看选择的数据库
3.2 创建和操作表
record field
整型
bit
tinyint
smallint
int
bigint
浮点型
double
float
decimal
decimal(a,b) b: 小数点位数
create table (if not exist) t_users()
create table customers(
cust_id int auto_increment primary key ,
cust_name varchar ( 50 ) not null ,
cust_age int check ( age>= 18 and age<= 60 ) ,
cust_sex bit not null default 0 ,
cust_address varchar ( 50 ) ,
cust_concat varchar ( 50 ) ,
unique ( cust_address)
) ;
show tables ;
show create table customers;
desc customers;
alter table tableName xxx [ column ] . . .
add
modify
change
drop
alter
rename
turncate table TableName
alter table customers change column cust_sex sex char ( 1 ) NULL default 'M' ;
添加主键
alter table customers add primary key ( cust_id) ;
alter table customers alter column cust_address set default 'BeiJing' ;
修改字段类型:
alter table customers modify column cust_name varchar ( 20 ) first ;
alter table customers modify column cust_id int auto_increment ;
alter table customers drop column cust_concat;
alter table customers rename to backup_customers;
like
as select * from customers
索引和完整性约束不会被复制
drop
第四章 表数据的基本操作
4.1 插入表数据
insert into customers values ( null , '李四' , default , '武汉市' , null )
ERROR 1366 (HY000): Incorrect string value: '\xCE\xE4\xBA\xBA' for column ...
windows平台默认的编码格式是gbk,所以在用命令行执行插入语句的时候命令行中的中文是gbk编码,与mysql 中的utf不同,导致出现这个错误,又因为mysql gui tools对中文支持不好,于是换了一个mysql图形工具,改用navicat,在这个软件中执行sql插入语句没有任何问题,成功插入。原来的数据库设置没有问题,是windows操作系统的默认编码格式和数据库冲突,而linux的默认编码格式为UTF-8,所以不会有这样的问题。特在这里记录下来,方便遇到同样问题的可以不像我这么费力。
用了navicat的命令列进行输入,就没有这个问题了
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ', null)' at line 1
insert into customers select cust_id . . . from customers_copy where cust_id= 2 ;
replace into customers values ( ) ;
4.2 删除表数据
delete from customers where cust_id= 2 ;
truncate ( table ) tablename;
4.3 修改表数据