MYSQL数据库

创建数据库

create database myDB;

删除数据库

drop database firstDB;

选择数据库

use myDB;

创建表

mysql> create table PEOPLE (
    -> ID int AUTO_INCREMENT PRIMARY KEY,
    -> NAME varchar(20) not null,
    -> PASSWORD tinyint(50) not null,
    -> AGE int not null,
    -> BIRTHDAY datetime);                                                     
Query OK, 0 rows affected (0.01 sec)

alter 修改表(列)字段

alter table PEOPLE MODIFY star int(2);

删除表

drop table users;

插入数据

insert into users (column1,column2,column3,..) values (value1, value2, value3, ...);

查询数据

//查询所有数据
select * from users;

//特定的列
select username,email from users;

//where条件查询
select * from users where is_active = true;

//升序
select * from users order by birthdate;

//降序
select * from users order by birthdate desc;

//limit限制返回的行数
select * from users limit 10;
where子句
//运算符and和通配符
select * from users where username like 'j%' and is_active = true;

//or
select * from users where is_active =true or birthdata < ‘2005-1-1’;

//IN
select * from users where birthdate in ('2005-1-1','2000-9-9','2000-8-8');

更新数据

update table_name set column1 = value1, column2 = value2,... where condition;

eg:
UPDATE orders
SET status = 'Shipped', ship_date = '2023-03-01'
WHERE order_id = 1001;

删除数据

DELETE FROM table_name WHERE condition;

like 模糊匹配

select column1, column2, ... from table_name where column_name LIKE pattern;
union 连接两个以上的select语句的结果,将其组合到一个结果集合,出去重复的行
SELECT column1, column2, ...
FROM table1
WHERE condition1
UNION
SELECT column1, column2, ...
FROM table2
WHERE condition2
[ORDER BY column1, column2, ...];

asc升序 desc降序

SELECT column1, column2, ...
FROM table_name
ORDER BY column1 [ASC | DESC], column2 [ASC | DESC], ...;

posted @   Yolololololo  阅读(9)  评论(0编辑  收藏  举报
(评论功能已被禁用)
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」

阅读目录(Content)

此页目录为空

点击右上角即可分享
微信分享提示