數(shù)據(jù)庫SQL語言總結(jié)

數(shù)據(jù)庫的創(chuàng)建、刪除、顯示

創(chuàng)建數(shù)據(jù)庫:

? ? ? ? create database + 庫名;

刪除數(shù)據(jù)庫:

? ? ? ? drop database + 庫名;

顯示數(shù)據(jù)庫:

? ? ? ? show database;

數(shù)據(jù)庫表的創(chuàng)建增刪改查

創(chuàng)建表

????????create table 表名(

??????????????? 字段名 數(shù)據(jù)類型? 屬性/約束(自增,非空)? 索引(主鍵,唯一)? 注釋,... ...? );

? ? ? ? ? ? ? ? ? 添加外鍵:constrants 外鍵名 foreign key(字段) references(主表字段)

? ? ? ? ? ? ? ? 表類型---engine:默認(rèn)innoDB

刪除表

????????????drop table 表名;

修改表

? ? ? ? ? alter table 表名 modify 字段名 字段屬性;

? ? ? ?? alter table 表名 change 原字段名 新字段名 字段屬性;

刪除列名

? ? ? ? alter table 表名 drop 字段名;

修改表名

? ? ? ? alter table 舊表名 rename to 新表名;

顯示表結(jié)構(gòu)

? ? ? ? dese 表名 ; ? ? ??

顯示表名稱

? ? ? ? show tables;

切換數(shù)據(jù)庫

? ? ? ? use 數(shù)據(jù)庫名;

清空表數(shù)據(jù)

? ? ? ? truncate 表名

數(shù)據(jù)庫內(nèi)容增刪改查

? ? ? ? 增:insert into 表名(列名)values(列值);

? ? ? ? 刪:delete from 表名;

? ? ? ? 改:update 表名 set 列名 = 列值,列名 = 列值? where 條件;

? ? ? ? 查:select * from 表名 where 條件;

? ? ? ? ? ? ? ? ? ? 條件:分組:group by ... having ...

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 排序:order by ... desc/asc

? ? ? ? ? ? ? ? ? ? ? ? ? ? ?? 截取條數(shù):limit

創(chuàng)建索引

? ? ? ? 普通:alter table 表名 add index/key ('列名');

創(chuàng)建外鍵

? ? ? ? alter table 從表名 add constraint 外鍵名 foreign key (‘從表名’)references 主表名(‘主表列’);

刪除索引

? ? ? ? alter table 表名 drop foreign key 索引名 ? ? ? ?

顯示索引

? ? ? ? show index/constraints from table

創(chuàng)建事務(wù)

? ? ? ? ? ? set autocommit = 0;

? ? ? ? ? ? start construction;

? ? ? ? ? ? sql語句

? ? ? ? ? ? commit;

? ? ? ? ? ? rollback;

? ? ? ? ? ? set autocommit = 1;

? ? ? ? ? ? ? ??

????????









最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容