重生之深度学习web前端(后端知识)第六天

create database timi
CHARACTER SET utf8
COLLATE utf8_general_ci;

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,'zw','123456','2004-05-11 09:05:05');
insert into user_info VALUES(null,'zjy','123456','2004-05-12 19:06:05');
insert into user_info VALUES(null,'znf','123456','2004-05-13 20:07:09');
insert into user_info VALUES(null,'yjy','123456','2004-05-14 21:08:10');
insert into user_info VALUES(null,'dlx','123456','2004-05-15 22:09:13');

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

-- 如果我只想查询账号名称
select username from user_info;

-- 查询zw的所有数据
select * from user_info where id=1;

-- 删除llocalhost_3306这条数据     delete from 表名 这是删除所有,如果有条件后面+ where
delete from user_info where id=1;

-- 修改zjy的密码为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,'9月22日正式服版本更新公告','2022:09:20 21:05:50');
insert into content VALUES(null,3,'9月22日正式服版本更新公告','2022:09:20 21:05:50');


SELECT * from content;

-- 查询热门的内容 
SELECT * from content where typeid=1;

-- 显示类型名称 两表联查,内连接查询(inner join on)
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 '9月22日%';

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值