有關(guān)MySQL的隨筆
1.索引(index):目的是通過索引找到要需要的列在表中那個位置演熟,然后直接去表中查找
基本語法:create index index_name on table_name(column_name[,column_name]...)
2.修改表結(jié)構(gòu):增刪列,修改列名,列屬性愤兵,添加主鍵(先確定是否not null,添加外鍵,關(guān)于表中的賦值,注意類型對應(yīng)贤笆、字符和日期記得加引號
-增加列:alter table table_name add column_name 類型(長度)
,刪除某列:alter table table_name drop column_name
-修改列名:alter table table_name change 舊列名 新列名 類型(長度)
-修改表名:alter table 舊表名 rename 新表名
或者rename table 舊表名 to 新表名
-修改列屬性:alter table table_name modify 列名 類型(長度)
-添加主鍵:alter table table_name add primary key(列名)
-添加外鍵:alter table table_nameA add foreign key(列名) references table_nameB(列名)
3.刪除表:整個表會消失讨阻,無法再被利用drop table table_name
清除表:清除表中的所有內(nèi)容芥永,不改變表結(jié)構(gòu)truncate table table_name
以及delete from table_name where column_name=value
4.插入數(shù)據(jù)的2種方法:
-一次輸入一筆:insert into table_name(column_name[,column_name...]) values (value[钝吮,value...])
-一次輸入多筆:運用select語句從另外一個表中指明要輸入的數(shù)據(jù) insert into table_nameA (column_name[埋涧,column_name...])select column_name[,column_name...] from table_nameB
當(dāng)然語法中還可以加入where奇瘦、group by棘催、having等關(guān)鍵字
5.修改(更新)表的內(nèi)容:需要使用到update語句
-update table_name set column_name=value[,column_name=value...] where column_name=value[耳标,...]
[參考資料](https://www.1keydata.com/cn/sql/sql-groupby.php)
[reference]:(https://www.cnblogs.com/sunxun/p/5676319.html)
[數(shù)據(jù)庫習(xí)題集網(wǎng)址](http://www.wodefanwen.com/lhd_4wefx0ad6f9acj29pw7y_4.html)