創(chuàng)建數(shù)據(jù)庫
creat database? databasename
刪除數(shù)據(jù)庫
drop database databasename
查詢數(shù)據(jù)庫
show database
創(chuàng)建表
creat table tablename(
列名 數(shù)據(jù)類型 屬性【自增 非空】 索引【主鍵 唯一】 注釋
列名之間用胆敞,隔開
)engine=innerdb charset=utf-8 注釋;
加外鍵 :constraint+外鍵名? foreign key 加列
刪表
drop table 表名
drop table 表名锈麸,表名,表名
修改列屬性
alter table 表名 modify 字段名 屬性
添加列
alter table 表名 add(列名 屬性)
刪除列
alter table 表名 drop(列名 屬性)
修改表名
alter table 舊表名 rename to 新表名
顯示表結(jié)構(gòu)
desc 表名
cmd里顯示所有表名稱
show tables
選中叼架、切換數(shù)據(jù)庫
use 數(shù)據(jù)庫名
數(shù)據(jù)庫內(nèi)容的增刪改查
增
?inster into?列名 values(內(nèi)容)
inster into 列名 values(內(nèi)容),(內(nèi)容)卒废,
刪
delete from 表名 where 加過濾條件
改
update 表名 set? 列名=列值 where 過濾條件
查
select * from 表名
where條件 and 或or鏈接
模糊查詢 like
分組 group by
分組后二次過濾 having
排序 order by???? desc?降序 ?asc升序
limite 限制個數(shù)
創(chuàng)建索引的三種方式
創(chuàng)建表時 直接寫
alter table tablename? add?? index‘多律、unquin’(列名)
創(chuàng)建外鍵
alter table 從表名 add? constraint 外鍵名 foreign key (‘從表列’) references 主表名(‘主表列’)
刪除索引或外鍵
alter table 表名 drop foreign key 索引名或外鍵名
顯示所有索引或外鍵
show index from索引名或外鍵名
事物的標準流程
set autocommit=0
start transaction
sql語句
commit / rollback
set autocommit=1