Create a database
1 Create database studentdb charset UTF8;
1 #Create a database2 CREATE Database Studentdb charset UTF8;3 #View the character set of a database4 Show Create database studentdb;5 #Create a data table6 CREATE TABLE students (7ID int auto_increment,#int represents a numeric type, char represents a string type8Name Char (32) notNull#Date represents the time type, and NOT NULL means cannot be null9Age int notNull#auto_increment represents self-incrementTenAddr char (32),#primary KEY (ID) represents ID as primary key OneRegister_date Date notNULL, APrimary key (ID));
# insert data into table INSERT into students (name, Age,register_date) VALUES ( " zhangchen " Span style= "COLOR: #800000" > ", 21," 2016-11-30 "); #insert into table name (field) VALUES (field corresponding value);
#查询数据表
Select * from students where ID >3 and >24;
SELECT * from students limit 7; #查询前7行
Select * FROM students limit 7 offset 2; #从第3行起往后查7行 offset defaults to 0
SELECT * from students where register_date like "2016-09%"; #模糊查询
#修改表
Update students set Name= "Xuxiaoyu" where age=22; #update table name set [field = value],[field = value] where age = 22;
Delete from students where name = "Liruixin"; #删除数据
SELECT * FROM students order by register_date ASC; The fields behind #order by are sorted in ascending order
SELECT * FROM students order BY register_date Desc; The fields behind #order by are sorted in descending order
Select Name,count (*) from students group by name; #分组统计 Count the number of people with the same name in this table
#字段操作
ALTER TABLE students add sex enum ("M", "F") not null; Add a field
ALTER TABLE students drop addr #删除一个字段
ALTER TABLE students modify sex enum ("F", "M") null; ALTER TABLE students modify age int (a); #修改字段的属性
MySQL Basic operation