MYSQL基本命令

查询已有的数据库:show databases;

 

对数据库的操作:

1、删除数据库:运行drop database +数据库的名称;

 

2、添加数据库:运行create database +数据库的名称;

 

对表的操作:

首先你要打开你要操作的表所在的数据库之后才可进行操作,运行use+数据库名称

 

查询数据库中的表:运行show tables;

 

1、添加表:create table +表名(id int,name varchar(20));

 

再次查询表的时候,多了一个表添加成功了

 

2、删除表:drop table o

 

再次查询表的时候可以发现少了一个os表,说明删除成功了。

 

对表中数据的操作

1、查询表中的内容:select * from student;

 

 多表连接查询:

内链接
select name, bobby_name from 表名 , 表名 where 条件
左外部链接
select user_name,hobby_name from 表名left join 表名 on 条件

2、删除表中的内容:delete from 表名 where 条件(注意:执行这一步操作的时候一定要谨慎,确保不会发生"从删库到跑路事件")

 

2、添加表中的内容:分为3种

    (1)单条:Insert into student(user_name, sex, birthday) values('小红','男','2001-09-18');

 

    (2)多条:Insert into student(user_name, sex, birthday) values('小明','男','2001-09-18'),('小明','男','2001-09-18'),('小明','男','2001-09-18');

 

    (3)插入查询结果:Insert into student(user_name,sex,birthday)(select user_name,sex,birthday from student where id=10);

 

原文地址:https://www.cnblogs.com/zym2000/p/9175933.html