后端数据库基本知识以及举例(王者荣耀数据)

数据库的增删改查

/*向当前这个用户表中添加数据*/

insert into user info values(  );

/*删除cs这条数据delete from 表名 这是删除所有,如果有条件后面+ where */

delete from user info where id=6 ;

/*修zw的密码为654321 update 表名 set你要修改的列名如果有条件后面+where */

update user info set passwords='654321'where id=7;

/*查询表中的所有数据*/

select *from user info;

查询sj的所有数据*/

select *from user info where id=8;

例子:

/* 创建一个库*/

create database timil;

/*进入数据库*/

use timi;

/*创建一个用户表*/

create table user_info(

id int primary key auto_increment,

username varchar(20) not null,

passwords VARCHAR(20) not null,

reg_date TIMESTAMP not null

)

/*向当前这个用户表中添加数据    insert into 表名 values(表中每列插入的具体数据)*/

insert into user_info values(null,'cs','123456','2024-05-11 09:05:05');

insert into user_info values(null,'zw','123456','2024-05-12 19:05:05');

insert into user_info values(null,'sj','123456','2024-05-13 20:05:05');

insert into user_info values(null,'zpf','123456','2024-05-14 06:05:05');

insert into user_info values(null,'cpy','123456','2024-05-15 19:35:05');

/*select *(这个*代表所有的表中字段),如果你只是查表中某个字段,这里就写某个字段 from 表名  查询表中的所有数据*/

/*如果我只是想查询账号,select username from user_info*/

select username from user_info;

/*查询表中的所有数据 */

select * from user_info;

/*查询sj的所有数据*/

select * from user_info where id=6;

/*删除cs这条数据     delete from 表名 这是删除所有,如果有条件后面+ where */

delete from user_info where id=1;

/*修改zw的密码为654321   update 表名 set  你要修改的列名  如果有条件后面+ where */

update user_info set passwords='654321' where id=2;

/*创建类型表*/

create table type(

id int primary key,

typename varchar(50) not null

)

/*向类型表中添加对应的数据*/

insert into type values(1,'热门');

insert into type values(2,'新闻');

insert into type values(3,'活动');

insert into type values(4,'赛事');

insert into type values(5,'公告');

select * from type;

/*创建内容表对应类型表  主外键关系 类型表里面的id作为主键,内容表里面的类型id作为外键*/

create table content(

id int primary key auto_increment,

typeid int references type(id),

content varchar(300) not null,

contentdate TIMESTAMP

)

/*向内容表中插入对应的数据*/

insert into content values(null,1,'9月22日正式服版本更新','2022:09:20 21:05;50');

insert into content values(null,2,'背《滕王阁序》免费得弈星新皮肤火热进行中','2022:09:20 21:05:50');

insert into content values(null,3,'互动小任务第18期-金秋主题头像框票选活动开启!','2022:09:20 21:05:50');

insert into content values(null,4,'姜子牙英雄品质升级共创-技能特效研讨活动开启','2022:09:20 21:05:50');

insert into content values(null,5,'峡谷夏日特别行动之地某有话说友好交流是胜利的关键','2022:09:20 21:05:50');

insert into content values(null,1,'蔡小姬探班手记|百里守约·碎云皮肤海报设计故事','2022:09:20 21:05:50');

insert into content values(null,2,'9月14日全服不停机更新公告','2022:09:20 21:05:50');

insert into content values(null,3,'姜子牙英雄品质升级共创-台词票选活动结果公布','2022:09:20 21:05:50');

/*查询content表*/

select * from content;

/*查询热门的内容 显示类型名称 两表联查,内连接查询(inner join on)*/

select * from content where typeid=1

select c.*,t.typename from content c,type t where t.id=c.typeid;

select c.*,t.typename from content c inner join type t on t.id=c.typeid;

/*查询热门和新闻的内容*/

select * from content where typeid=1 or typeid=2;/*不建议*/

select * from content where typeid in(1,2);

/*查询内容里面有开启的内容 模糊查询的关键字 like*/

select * from content where content like '%开启%';

/*查询内容里面有公告开头的*/

select * from content where content like '姜子牙%';

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值