共計 1329 個字符,預(yù)計需要花費(fèi) 4 分鐘才能閱讀完成。
自動寫代碼機(jī)器人,免費(fèi)開通
這篇文章將為大家詳細(xì)講解有關(guān)數(shù)據(jù)庫的核心操作是什么,丸趣 TV 小編覺得挺實(shí)用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
數(shù)據(jù)庫的最核心也是最常用的操作是增刪改查。
數(shù)據(jù)庫
查詢數(shù)據(jù)庫:show databases;
創(chuàng)建數(shù)據(jù)庫:create database 庫名;
刪除數(shù)據(jù)庫:drop database 庫名
表
創(chuàng)建表:create table 表名 (字段名 數(shù)據(jù)類型【屬性】【索引】)
查看表結(jié)構(gòu):desc 表名
查看表:show tables
插入數(shù)據(jù):insert into 表名 value()
查看創(chuàng)建表信息:show create table 表名
查看指定庫的表:show tables where 目標(biāo)庫名
字段
增加:alter table 表名 add 字段名 數(shù)據(jù)類型【屬性】【索引】
往指定位置后面插入字段:alter table 表名 add 字段名 數(shù)據(jù)類型【屬性】【索引】after 指定的字段名
往第一個位置插入:alter table 表名 add 字段名 數(shù)據(jù)類型【屬性】【索引】first
刪除:alter table 表名 drop 字段名
修改:alter table 表名 change 舊字段 新字段 數(shù)據(jù)類型【屬性】【索引】
條件語句: = = != and or 等等
數(shù)據(jù)
添加:insert into 表名 value()
刪除:delete from 表名(慎用,刪除整個表數(shù)據(jù))
delete from 表名 where 條件語句
修改:update 表名 set 字段名 = 值 where 條件語句
★查詢:精確查詢:select * from 表名 where 條件語句
運(yùn)算符查詢:select * from 表名 where id = 1+1
select * from 表名 where id 100
邏輯查詢:select * from 表名 where and 條件
select * from 表名 where or 條件
模糊查詢:select * from 表名 where 列名 like 值 值:%a%(查找中間有 a 的數(shù)據(jù)) a%(查找以 a 開頭的數(shù)據(jù)) %a(查找以 a 結(jié)尾的數(shù)據(jù))
排序與受限查詢:select * from 表名 where order by 列名 desc desc:表示從大到小排序 asc:表示從小到大排序
select * form 表名 limit x,y x:表示跳過多少條 y:表示去多少條
聚合排序:select count(列名) from 表名
count:計算表中某個列或多個列中數(shù)據(jù)的次數(shù)
avg:平均值
max:最大值
min:最小值
sum:總和 一般用于計算價格
區(qū)間查詢:select * from 表名 where 字段 between 0 and 10 查找 0 到 10 區(qū)間的數(shù)據(jù)
分組查詢:select 展示的列 from 表名 group by 參考列
select name,count(列) from 表名 group by name
select name,count(content) from 表名 group by name having count(content) 5 having 是在聚合的基礎(chǔ)上再篩選
分組查詢一般與聚合查詢一起使用
關(guān)于“數(shù)據(jù)庫的核心操作是什么”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,使各位可以學(xué)到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
向 AI 問一下細(xì)節(jié)