mysql具體語句樣本

來源:互聯網
上載者:User

標籤:

建表:(not null ,auto_increment, unique , primary key)create database balfish;
use balfish;
create table mytable1(
    id int not null,
    name varchar(20),
    grade int
);

insert into mytable1 values(‘1‘,‘yang‘,97);
insert into mytable1 values(‘2‘,‘li‘,94);
insert into mytable1 values(‘3‘,‘chen‘,88);
insert into mytable1 values(‘4‘,‘zhang‘,57);
insert into mytable1 values(‘5‘,‘dai‘,90); create table mytable2(
    id int not null,
    name varchar(20),
    job varchar(20)
);

insert into mytable2 values(‘1‘,‘yang‘,‘worker‘);
insert into mytable2 values(‘2‘,‘li‘,‘farmer‘);
insert into mytable2 values(‘3‘,‘shi‘,‘doctor‘);  select:select * from mytable1 order by grade desc limit 0,2;   inner join(1) select * from tb1,tb2 where tb1.name=tb2.name;(2) select * from tb1 inner join tb2 on tb1.name=tb2.name; outerselect * from mytable1 tb1 left join mytable2 tb2 on tb1.name=tb2.name;    insert一次插入多個.      insert into city(id,city_name) values(1,’beijing’),(2,’shanghai’); 當insert時表中存在唯一性限制式時,方法1:insert into tbl_name(a, b, c) values(?,?,?) on duplicate key update c=values(c);方法2:Insert ignore into tbl_name (a,b,c) values(1,2,3);    updateupdate product set amount=150 where id=1;update product_details set weight=38,exist=1 where name=‘Jim‘;update tbl_name set b=b+1 where name=‘aaa’;    deleteDELETE FROM orderlog where user = ‘Sean‘ and id between 20000 and 40000;  truncate– 特點
屬於DDL操作,執行後立即生效無法復原
等同於delete from tb,刪除全表資料,保留空表
需要drop許可權
文法:truncate table product;     create table
通過表來建表(1)create table t1 select * from product;   建立一個和原表欄位結構一致的新表,去掉所有的約束,同時將原表select的結果資料插入新表  (2)create table t2 like product;  建立一個和原表結構完全一致的新空表,包含全部約束       alter table欄位操作: alter table add/modify/drop column ...alter table t2 add column contact varchar(50);
alter table t2 modify column contact varchar(500);
alter table t2 drop column contact; 索引操作:alter table t2 add index idx_orderno(orderno);
alter table t2 drop index idx_orderno;
alter table t2 add primary key(id);
alter table t2 add unique index uniq_version(version);  drop table– 特點
• 刪除表操作,清除全部資料,刪除表定義檔案
• 不可復原
• 文法:drop table t2;   儲存引擎:– MyISAM
不支援事務
表級鎖
只能緩衝索引
表檔案在大批次更新操作後可能損壞
– InnoDB (目前線上使用的引擎)
支援事務
行級鎖,提高了並發性
buffer pool中快取資料和索引
不會損壞   Index索引是儲存引擎用於快速定位元據的一種資料結構 • 索引掃描
主鍵----直接在Clustered B+Tree上查詢
 輔助索引----在Secondary B+Tree上查詢到主鍵 ,然後 用主鍵在Clustered B+Tree  

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.