nodejs的基本使用(三)mysql基本使用

DataType数据库字段类型

数据中字段有很多类型以下只是常用的。

类型
int 整数
varchar 字符串
tinyint 数值布尔

表的特殊标识

当创建表的时候会有一写特殊标识可供选择:

标识符
PK 主键唯一标识符
UQ (Unique) 值唯一,不能出现重复
AI (auto increment) 自动增长
NN (not null) 值不允许为空

SQL语法

select语句

-- 从一个表中查询所有数据
# select * from 表名称

-- 从指定的表里查询指定的列名
#select 列名称 from 表名称

-- 通过星号获取users表中所有的数据
select * from users
-- 从users表中获取 username 和 password 的数据
select username,password from users

insert into语句

向表中插入数据。

-- 向表中插入数据
# insert into 表名(列1,列2...) values (值1,值2...)

-- 向user表中插入 username为tony stark,password为 098123的用户
insert into users(username,password) values ('tony stark','098123');

update语句

用于更新数据

-- 语法解读:
-- 1.用update 指定更新那个表中的数据
-- 2.用set 指定列对应的值
-- 3.用where 指定更新条件
# update 表名 set 列名=新值 where 条件

-- 把用户id为1的密码修改为 666666
update users set password='ls666666' where id=1;

-- 把用户id为2的用户密码和状态更新为 admin123 和 1
update users set password='admin123',status=1 where id=2;

delete from语句

用于删除数据

-- 用于删除
delete from 表名 where 条件

-- 删除users中id为5的用户
delete from users where id=5;

where 子句

where作用限定选择的标准

# 查询语句 中的 where
select 列名称 from 表名称 where 列 运算符 值

# 更新语句中的where
update 表名 set=新值 where 列 运算符 值

# 删除语句中的 where 条件
delete from 表名 where 列 运算符 值

where子句中的运算符

= 等于

<> != 不等于

‘>’ 大于

‘<’ 小于

‘<=’ 小于等于

‘>=’ 大于等于

between 在某个范围

like 搜索某种模式

演示where字句的使用

-- where字句的使用
-- 查询状态等于1的用户
select * from users where status=1
  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值