標籤:rem odi bsp 資料 預設 data count int ase
建立資料庫
1 create database studentdb charset utf8;
1 #建立資料庫 2 create database studentdb charset utf8; 3 #查看資料庫的字元集 4 show create database studentdb; 5 #建立資料表 6 create table students( 7 id int auto_increment, #int 代表數字類型,char 代表字串類型 8 name char(32) not null, #date 代表時間類型, not null 代表不可為空 9 age int not null, #auto_increment 代表自增10 addr char(32), # primary key (id) 代表id 為主鍵11 register_date date not null,12 primary key (id));
#插入資料到表insert into students (name,age,register_date) values ("zhangchen",21,"2016-11-30"); #insert into 表名 (欄位)values (欄位對應的值);
#查詢資料表
select * from students where id >3 and age >24;
select * from students limit 7 ; #查詢前7行
select * from students limit 7 offset 2; #從第3行起往後查7行 offset 預設為0
select * from students where register_date like "2016-09%"; #模糊查詢
#修改表
update students set name="xuxiaoyu" where age=22; #update 表名 set [欄位=值],[欄位=值] where age = 22;
delete from students where name = "liruixin"; #刪除資料
select * from students order by register_date asc; #order by 後邊的欄位按升序排序
select * from students order by register_date desc; #order by 後邊的欄位按降序排序
select name,count(*) from students group by name; #分組統計 統計這個表中相同名字的人數
#欄位操作
alter table students add sex enum("M","F") not null; 增加一個欄位
alter table students drop addr #刪除一個欄位
alter table students modify sex enum("f","m") null; alter table students modify age int(20); #修改欄位的屬性
mysql 基本操作