Mysql系列课程--第一章 Sql分类 常用命令

一.数据规范化
1.第一范式
二维表格,不存在重复的行与列
2.第二范式
满足第一范式,不存在部分依赖
3.第三范式
满足第二范式,不存在传递依赖

二.sql分类
1.DDL:针对于数据库对象:数据库,表,列.关键字:create,alter,drop
2.DML:针对于表数据操作,关键字:insert ,delete,update
3.DCL:针对于访问权限和用户
4.DQL:针对于表查询,关键字:select ,from ,where

三.命令

1.登陆mysql数据库

mysql -uroot -proot
-u:用户
-p:密码

DDL:
2.查看有哪些数据库

show databases;

3.删除yz数据库

drop database yz;

4.使用哪个数据库

use mysql;

5.查看数据库下有哪些表

show tables;

6.查看user这张表字段

desc user;

7.创建数据库

create database yz;

8.创建表

 create table teacher(name varchar(20) not null,age int,sex varchar(10) );

9.删除表

 drop table student;

10.添加表字段

alter table teacher add column iphone int;
alter table teacher add column money decimal(5,2);//一共5位,小数点后2位
alter table teacher add column birthday datetime;

11.删除表字段

alter table teacher drop column iphone;

12.修改表字段

alter table teacher change birthday birth date;// birthday字段改为 birth

DML:
1.插入表数据

insert teacher values('aa',18,'a');

2.修改表数据

update teacher set age=38 where name='aa';

3.删除表数据

delete from teacher where name = 'cc';

4.清空表数据

delete from teacher;
truncate table teacher;

DQL:
1.查询数据

select * from teacher;
select name,age from teacher;

详细课程查询:
Mysql系列课程–第一章 Sql分类 常用命令
Mysql系列课程–第二章 约束 自增主键
Mysql系列课程–第三章 建表 插数据
Mysql系列课程–第四章 备份 普通查询
Mysql系列课程–第五章 高级查询 表连接 子查询 case when
Mysql系列课程–第六章 索引和视图
Mysql系列课程–第七章 触发器和存储过程
Mysql系列课程–第八章 sql精选35道题

猜你喜欢

转载自blog.csdn.net/u012843355/article/details/78632880
今日推荐