標籤:add 許可權 core 自動 公司 primary 員工 show 開始
索引:一種快速定位技術,相當於一本書的目錄頁.作用:快速查詢資料 條件:資料條目大於2000條create index id_index on info (id); //建立普通索引show index from info \G //查看索引drop index id_index from on info; //刪除索引create unique index unique_id_index on info (id); //建立唯一索引alter table info add primary key (id); //建立主鍵索引(已經建立了表,沒有指定主鍵,然後修改表加入主鍵,主鍵索引會自動建立)alter table info change id id int(10);//刪除自增長alter table info drop primary key;//刪除主建alter table info add column age int; //添加列alter table info drop column age int; //刪除列create table infos (descript TEXT,FULLTEXT(descript)); //建立全文索引create index multi_index on info(name,address); //建立多列索引事務:一組操作共同執行或者都不執行,結果保持一致。特性:原子性、一致性、隔離性、持久性。例如:銀行轉賬
| 姓名 |
餘額 |
條件:餘額>0 |
| Zhangsan |
100 |
/ |
| lisi |
200 |
/ |
註:Zhangsan 轉賬100給 to lisi
事務固定格式:
begin 開始
Update bank set money=money+100 where name=’lisi’
Update bank set money=money-100 where name=’zhangsan’
commit 提交
rollback 復原
補充:set autocommit = 1; //開啟自動認可set autocommit = 0; //禁止自動認可savepoint s2; //定義復原點rollback to savepoint s2; //復原到S2 (相當於虛擬機器還原快照)視圖:視圖是 資料庫中的虛擬表。作用:一張表中的資料給不同的許可權使用者提供訪問舉例:公司員工績效工資考核表:
| 工號 |
姓名 |
年齡 |
崗位 |
績效 |
工資 |
| 1 |
Tom |
50 |
總裁 |
/ |
100萬 |
| 2 |
Jerry |
40 |
總監 |
90 |
20萬 |
| 3 |
charry |
30 |
雲端運算工程師 |
80 |
12萬 |
| 4 |
Jack |
24 |
雲端運算工程師 |
90 |
15萬 |
文法: create view 視圖名稱 AS select 語句create view scoreview as select from info where score > 80; //建立視圖(條件:成績>80)select * from score_view; //查看視圖update score_view set score=88 where id=1; //id1的成績更新為88drop view if exists score_view; //刪除視圖總結:1.資料庫索引分為普通索引、唯一性索引、主鍵索引、全文索引、多列索引;2.資料庫索引可以協助快速查詢表中資料,但並不是任何欄位都需要建立索引;3.資料庫事務的ACID特性:原子性、一致性、隔離性、持久性;4.MySQL事務命令有begin、rollback、commit、savepoint;
Mysql索引、事務、視圖 常用命令及要點歸納