项目中常用的sql

1、建库

CREATE DATABASE `xd_study`;

USE `xd_study`;

2、建表

create table Student(
	Sno char(7) primary key comment '学生编号',
    Sname char(10) not null comment '学生姓名',
    Sex char(2) comment '学生性别',
    Birthdate date comment '出生日期',
    Dept varchar(20) comment '所在系'
)ENGINE=INNODB DEFAULT CHARSET=utf8 ;

3、插入数据

INSERT  INTO `student`(`Sno`,`Sname`,`Sex`,`Birthdate`,`Dept`)VALUES 
('2020001','张三','男',now(),'计算机');

4、查询

select * from student

# 条件查询
select * from student where sname=`张三`

# 模糊查询
select * from student where sname=`%三`

# 多表联查
select sc.sno,student.sname,sc.grade
from SC 
inner join student 
on sc.sno=student.sno
# 修改
update student set sname = '李四' where sno = '2020001'
# 删除
delete from student;

你可能感兴趣的:(mysql)