HeidiSQL中一些简单mysql语句的含义(一)

一、创建数据库

#创建一个数据库,这个是数据库的名字叫java62

create database java62;

#删除数据库java62

drop database java62;

#查看当前mysql里的所有数据库

show databases;

#创建student表,varchar括号里的是字符串的长度

create table student(no int ,name varchar(10),age int);

#查看当前数据库里有哪些表

show tables;

#删除student表

drop table student;

二、增删改查

#向student 表中插入数据

insert into student (no,name,age) values (1001,'张三',20);

#插入两条数据

insert into student (no,name,age) values(1002,'李四',21),(1003,'王五',22);

注:如果不想某个字段重复,可以给它设置主键

#当我要给表中每个字段都写入数据的时候,可以不写字段名

#如果给部分字段赋值,则必须写字段名

insert into student values (1004,'测试',20);

#删除表中所有数据

delete from student;

#在student表中删除no=1004的数据

delete from student where no=1004;

#把所有数据进行修改

update student set age=23 ;

#把 no=1003的一条数据中age改为23

update student set age=23 where no=1003;

#年龄加1

update student set age=age+1 where no=1003;

#把no=1003中name改为测试2,age改为20

update student set name='测试2',age=20 where no=1003;

#查询表中所有数据

select * from student;

#查询name的所有数据

select name from student;

#查询name和age

select name,.age from student;

#查询张三的所有数据

select * from student where name='张三';

#查询age>20的数据

select * from student where age>20;

#查询 name='张三' 或者age=21的数据

select * from student where name='张三' or age=21;

#查询 name='张三' 并且age=21的数据

select * from student where name='张三' and age=21;

相关推荐
RestCloud3 小时前
揭秘 CDC 技术:让数据库同步快人一步
数据库·api
得物技术6 小时前
MySQL单表为何别超2000万行?揭秘B+树与16KB页的生死博弈|得物技术
数据库·后端·mysql
可涵不会debug10 小时前
【IoTDB】时序数据库选型指南:工业大数据场景下的技术突围
数据库·时序数据库
ByteBlossom10 小时前
MySQL 面试场景题之如何处理 BLOB 和CLOB 数据类型?
数据库·mysql·面试
麦兜*11 小时前
MongoDB Atlas 云数据库实战:从零搭建全球多节点集群
java·数据库·spring boot·mongodb·spring·spring cloud
Slaughter信仰11 小时前
深入理解Java虚拟机:JVM高级特性与最佳实践(第3版)第十章知识点问答(10题)
java·jvm·数据库
麦兜*11 小时前
MongoDB 在物联网(IoT)中的应用:海量时序数据处理方案
java·数据库·spring boot·物联网·mongodb·spring
努力也学不会java11 小时前
【设计模式】抽象工厂模式
java·设计模式·oracle·抽象工厂模式