navicat的mysql数据库基础知识总结
基本命令
DDL
启动mysql的方法是cmd中输入
mysql -u用户名 -p密码
操作数据库:
操作表格:
DML
--查询所有数据
SELECT*FROM
student;
--给指定列添加数据
INSERT into student(id,name) values(1,"张三");
--给所有列添加数据
INSERT into student(id,name,gender,birthday,score,email,tel,status) VALUES (2,'李四','男','1991-11-11',99.99,'2222@qq.com','13888888888','1');
--可以不写student,表示全选数据,但是后期开发建议写数据
INSERT into student VALUES (2,'李四','男','1991-11-11',99.99,'2222@qq.com','13888888888','1');
INSERT into student(id,name,gender,birthday,score,email,tel,status) VALUES (2,'李四','男','1991-11-11',99.99,'2222@qq.com','13888888888','1');
INSERT into student(id,name,gender,birthday,score,email,tel,status) VALUES (2,'李四','男','1991-11-11',99.99,'2222@qq.com','13888888888','1');
INSERT into student(id,name,gender,birthday,score,email,tel,status) VALUES (2,'李5','男','1991-11-11',99.99,'2222@qq.com','13888888888','1');
--修改数据UPDATE表名SET
update student set gender='女' where name ='李四';
update student set birthday='1991-12-12',score=99.01,where name='李四';
--注意:如果没有where,将修改全部值
update student set gender='男';
--删除
delete from student where name='张三';
--delete from student 表示删除所有的数据
DQL
CREATE TABLE dql(
id int,
name VARCHAR(20),
age INT,
sex VARCHAR(5),
address varchar(100),
math double(5,2),
english double(5,2),
hire_date DATE
);
INSERT INTO dql(id,name,age,sex,address,math,english,hire_date)
VALUES
(1,'马芸',55,'男','杭州',66,78,'1995-09-01'),
(2,'马花藤',45,'女','深圳',98,87,'1998-09-01'),
(3,'马斯克',55,'男','香港',56,77,'1999-09-02'),
(4,'柳白',20,'女','湖南',76,65,'1997-09-05'),
(5,'柳青',20,'男','湖南',86,NULL,'1998-09-01'),
(6,'刘德华',57,'男','香港',99,99,'1998-09-01'),
(7,'张学右',22,'女','香港',99,99,'1995-09-01'),
(8,'德玛西亚',18,'男','南京',56,65,'1994-09-02');
--查询地址信息
SELECT address from dql;
--去除重复记录
SELECT DISTINCT address from dql;
--查询姓名,数学成绩,英语成绩,并且用as重命名
SELECT name,math as 数学成绩, english as 英语成绩 from dql;
--查询年龄大于等于20岁的成员
SELECT * from dql where age >=20;
--查询年龄大于等于20岁 并且 年龄 小于等于30岁的学员
SELECT * from dql where age >= 20&&age <= 30;
SELECT * from dql where age>=20 and <=30;
SELECT * from dql where age BETWEEN 20 and 30;
--查询入学日期在1998,9,1 到 1999