SQL语句(基础)

01.表操作

1.1 创建表

create table students(
    id int unsigned primary key auto_increment,
    name varchar(20),     # 姓名长度为 20
    age int unsigned,     # 年龄为正整数
    height decimal(5,2)    # 升高最大5位数,可以保留两位小数
)

1.2 删除表

drop table students
或
drop table if exists students

02.增删改查

2.1 查

例:查询所有学生数据
select * from students

2.2 增

# 例1:插入一条学生
insert into students values(0,'亚瑟2',23,167.56)
# 例2:插入多个学生,设置所有字段的信息
insert into students values(0,'亚瑟3',23,167.56),(0,'亚瑟4',23,167.56)

2.3 改

update students set name='狄仁杰',age=20 where id=5

2.4 删

delete from students where id=6
原文地址:https://www.cnblogs.com/chao460/p/14752763.html