--创建数据库
create database sqltest
--创建表
create table test {
id int not null primary key,
name varchar(50),
age int
}
--增
insert into test values (2, "test2", 21);
--查
select * from test;
select name, age from test where id = 1;
--改
update test set name = "test3" where id = 2;
--删
delete from test where id = 2;
--表连接查询
select name from teacher where id = (select teacher_id from student where name = "zs")
--查询test表中的数据条数
select count(*) from test
select count(*) from test where age = 21;
select count(*) from test where age>21 and age<30
--降序排列
select * from test order by id desc
--主键id改为自增
alter table 表名 change id id int AUTO_INCREMENT
--查询最后10条数据
select * from 表名 order by id(主键) desc limit 10
参考连接:
sql基础入门——mysql与navicat连接