基础数据库语句,初学者可以学习(方便自己)

本文介绍了数据库的基础操作,包括创建名为student3的表,展示了插入数据的示例,并详细列举了多种查询语句的用法,如按年龄条件筛选、使用IN和BETWEEN操作符、LIKE关键字进行模糊匹配等。此外,还涉及了对NULL值的查询及ALTER TABLE修改表结构的示例,是初学者实践数据库操作的好材料。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天我学习了数据库一些相关的东西,对于刚刚学习数据库的同学可以试一下!!!

1:下面我们建立一张student3的表:

create table student3(
    id int,
		name varchar(20),
		age int,
		sex varchar(5),
		address varchar(100),
		math int,
		english int
);
insert into student3(id,name,age,sex,address,math,english) 
VALUES(1,'马云',55,'男','杭州',66,78),(2,'马化腾',45,'女','深圳',98,87),(3,'马景涛',55,'男','香港',56,77),(4,'柳岩',20,'女','湖南',76,65),(5,'柳青',20,'男','湖南',66,78),(6,'刘德华',57,'男','香港',99,99),(7,'马德',22,'女','香港',99,99),(8,'德玛西亚',18,'男','南京',56,65)

2:这里就是一些查询语句

>--查询年龄大于20岁的
	>select * from student3 where age>20
	>--查询年龄等于20岁的         
	>select * from student3 where age=20
	>--查询年龄不等于20岁的
	>select * from student3 where age!=20
	>select * from student3 where age <> 20
	>
	>--查询年龄大于20,小于等于30的
	>select * from student3 where age>=20&&age<=30
	>select * from student3 where age>=20 and age<=30
	>select * from student3 where age BETWEEN 20 and 30;
	>
	>--查询年龄22岁,19岁,25岁的信息
	>select * from student3 where age=22||age=19||age=25 
	>select * from student3 where age in(19,22,25)
	>
	>--查询一下英语成绩为null的人
	>select * from student3 where english=null;   //这是错误的
	>select * from student3 where english is null;
	>
	>--查询英语成绩不是null的
	>select * from student3 where english is not null
	>
	>--查询其中姓马的有哪几个
	>select * from student3 where name like '马%'
	>
	>alter table student3 change sex sexs varchar(110);
	>
	>--查询第姓名二个字是华的人
	>select * from student3 name
	>
	>--查询姓名是3个子的人
	>select * from student3 where name like '___'
	>
	>--查询姓名中包含'马的人'
	>select * from student3 where name like '%马%'
	>
	>--查询姓名中包含德的人
	>select * from student3 where name like '%德%'

3:点个关注不迷路 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值