1. Create a table Teacher in mysql:
create table Teacher(
teaId int not null,
teaname varchar(100),
age int,
sex enum('M', 'F'),
phone int);
Notice:
Difference between char and varchar:
‘123’ ------>varchar(10) # 3位
'123 ' -------> char(10) # 10 digits, less than 10 digits are filled with spaces
2. Create a super user:
grant all privileges on *.* to 'fxq'@'%' identified by '123456' with grant option;
3. Data query:
select * from Teacher where id >20
select * from Teacher where id in(10,20,30)
select * from Teacher where id like ('%1001%')
Query duplicate data:
select * from Teacher where group by teaname having count(*) >1;
Joint query:
select * from a,c where a.id = c.组id
View the table structure:
show create table_name
desc table_name
4. Insert data:
insert into table_name(id,name,age) values(1,'feng',20);
Insert multiple rows of data:
insert into table_name(id,name,age) values(1,'feng',20),(2,'zhang',30),(3,'wang',40);
5. Delete data:
delete from table where 条件判断
truncate table_name; #清空数据
drop table_name; #删除表
6. Update data
update table_name set 列名=XXXX,where 条件;
7. Create an index:
create index 库名_表名_列名1_列名2 (列名1,列名2)