create table courses ( id int unsigned auto_increment not null, name char(10) not null,primary key (id,name));
create table courses ( id int unsigned auto_increment not null permary key, name char(10) not null);
show table status like "courses"\G
alter table courses engine myisam
show index from courses;
create table courseBak select * from courses where id<5;
create table test like courses;
alter table test add unique (name);
alter table test change name names varchar(20) not null;
alter table test add starttime date not null default "2020-4-13";
alter table test rename to testcourses;
rename table testcourses to test;
alter table student add foreign key foreign_1 (id) references courses (id);
show create table student; #获取fk_symbol
alter table student drop foreign key fk_symbol;
select sid,name,id from student where id=3;
select * from student;
select * from students where age>=20;
select * from students where TID<=>NULL;
select * from students where age+5 > 30;
select * from students where not (SID>4 or gender="F");
%代表任意字符
_代表单个任意字符
select * from students where name like "y%"
select * from students where name rlike "[1].*$";
select * from students where age IN (18,20) and gender="F";
select * from students where TID is not NULL;
select distinct gender from students;
select * from students where SID < 8 limit 2,3;
select * from students where TID is not NULL order by CID1 DESC;
select name as test from students
Select avg(age) from students where denger=”F”;
select avg(age) from students group by gender;
select count(CID2),CID2 from students group by CID2 having count(CID2) >= 2;
select sid,name,course from student,courses;
select sid,name,course from student,courses where student.id=courses.id;
… left join … on
select SID,name,CID1,course from students left join courses on students.CID1=courses.id;
…right join … on
select * from students right join courses on students.CID1=courses.id;
select s.name as student,c.name as teacher from students as s,students as c where s.TID=c.SID;
select name,age from students where age> (select avg(age) from students);
select name,CID1,CID2 from students where CID1 in (select CID2 from courses);
select students.name,courses.course,students.SID,tutors.tname from courses,students,tutors where students.CID1=courses.TID AND courses.TID=tutors.TID;
(select * from courses) union (select CID1,name FROM students);
子查
NOT IN couuses.CID2 不在students.TID中的行
select CID2 from courses CID2 not in (select TID from students WHERE TID IS NOT NULL);
create index name_index_test on student (id);
索引的length指定索引时比较的位数,用sub_part表示
ASC 升序
DESC 降序
ydm ??
原文:https://www.cnblogs.com/zoer/p/12996744.html