alter 語句
// 修改數據庫編碼 utf8
alter database DBNAME character set utf8 collate utf8_general_ci;
// 增加索引
alter table DBNAME add index `new_index`(id)
可以代替index的有
primary key
unique
fulltext 全文搜索只有在 MyISAM 引擎中可用
// 另一種增加索引方法
create index 索引文件名 on 表名( 字段名)
// 刪除索引
alter table DBNAME drop index 索引文件名
// 另一種刪除索引方法
drop index 索引文件名 on 表名
// 刪除字段
alter table DBNAME drop column 字段名
// 停止更新 MyISAM 表中的非唯一索引。
alter table DBNAME disable keys;
插入大批量的數據之後
// 重新創建丟失索引
alter table DBNAME enable keys;
上面的操作能讓大批量的數據在寫入到數據表時加快執行速度。
// 複製表
create table A select * from B;
將B表的所有數據和字段全部複製到 A表。但是不會複製任何的屬性 和索引之類的東西。
// 如果想創建表時建立索引 則可以如下使用
create table A (primary key(id)) select * from B;
將B表的數據複製到 A 表時 設置 id列爲主鍵
完全複製 B 表的屬性和索引 ( 數據不會被複制)
create table A like B;
刪除多個表中的行
a 表
id name
1 test
b表
id aid
1 1
c表
id bid
1 1
delete a,b,c from a,b,c where a.id = b.aid and b.id = c.bid
如果上述刪除看作是查詢時只有在鏈表成功 纔會刪除 a b c 三個表中的三行記錄
具體條件成立時刪除那個表的數據 是看 delete 後面緊跟着的表名
導入txt 文本中的數據
load data infile 文本文件路徑 into table 表名 fields
terminated "," escaped by "\\" lines terminated by '\n'
terminated "," 指的是 用來 , 分割列
escaped by "\\" 不知道啥意思 不寫也行 (好像是對轉移的處理)
terminated by '\n' 指的是用什麼分割一行 (默認好像就是 \n)