Skip to content

wwc04/Database

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 

Repository files navigation

数据库常用命令

DDL(数据定义语言,用来定义数据库对象(数据库,表,字段))

数据库

--1.查询所有数据库

show databases;

--2.查询当前数据库

select database;

--3.使用/切换数据库

use 数据库名;

--4.创建数据库

create database [if not exists] 数据库名 [default charest utf8mb4];

--5.删除数据库

drop database [if exist] 数据库名;

--1.创建表

create table tablename(
   字段1 字段类型 [约束] [comment 字段1的注解]
   字段2 字段类型 [约束] [comment 字段2的注解]
   ......
)[comment 表注解]

表设计

--2.查询表

1)查询当前数据库所有表

show tables;

2)查询表结构

desc 表名;

3)查询建表语句

show create table 表名;

--3.修改表

1)添加字段

alter table 表名 add 字段 数据类型(长度) [comment 注解] [约束];

2)修改字段类型

alter table 表名 modify 字段名 新数据类型(长度);

3)修改字段名

alter table 表名 change 旧字段 新字段 数据类型(长度) [comment 注解] [约束];

4)删除字段

alter table 表名 drop colum 字段名;

5)修改表名

alter table 旧表名 rename to 新表名;

--4.删除表

drop table [if exists] 表名;

DML(数据操作语言,用来对数据库表中的数据进行增删改)

添加数据

--1.指定/全部字段添加数据

insert into 表名(字段1,字段2) values(值1,值2);
insert into 表名 values (值1,值2,...);

--2.指定/全部字段批量添加数据

insert into 表名(字段1,字段2) values(值1,值2)(值1,值2)...;
insert into 表名 values (值1,值2,...)(值1,值2,...);

修改数据(不加where会对整个表进行修改)

update 表名 set 字段1 = 值1 ,字段2 = 值2 ... ,where 条件;

删除数据

delete from 表名 where 条件;

DQL(数据查询语言,用来查询数据库中的表记录)

基本查询

条件查询

分组查询

排序查询

分页查询

About

数据库学习笔记

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published