mysql 基本操作

來源:互聯網
上載者:User

標籤: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 基本操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.