數(shù)據(jù)庫

  1. 概念:

    按照數(shù)據(jù)結(jié)構(gòu)來組織、管理、存放數(shù)據(jù)的庫

    數(shù)據(jù)庫=表+表之間的關(guān)系

  2. 常見數(shù)據(jù)庫

    MySQL、Oracle、MongoDB、SQLServer、Redis、Sqlite

  3. 數(shù)據(jù)庫與SQL的關(guān)系

    數(shù)據(jù)庫是用來存放數(shù)據(jù)的,SQL語句用來操作數(shù)據(jù)庫的數(shù)據(jù)

  4. MySQL

    1. 卸載:關(guān)閉服務(wù)、卸載軟件MySQL、刪除安裝MySQL路徑剩余的文件、ProgramData的MySQL文件刪除
    2. 安裝:雙擊 → ... → 安裝類型(Custom)→ 修改安裝路徑 → finish
    3. 配置
    4. 關(guān)閉開啟服務(wù)
    5. 登錄:mysql -u root -p123
    6. 退出:exit、ctrl+c
  5. SQL語句

    1. DDL:數(shù)據(jù)庫定義語言

      # 庫
      create database 庫名;
      show databases;
      use 庫名;
      drop database 庫名;
      show create database 庫名;
      
      # 表
      show tables;
      show tables from 其他庫名;
      create table 表名(
          id int primary key auto_increment,
          name varchar(20) unique not null,
          salary float(6,2),
          birthday date
        );
      desc 表名;
      drop table 表名;
      
      # 如果插入中文
      # 通知服務(wù)器客戶端使用的編碼是gbk
      set character_set_client=gbk;
      
      # 通知服務(wù)器客戶端查看結(jié)果集使用的編碼是 gbk
      set character_set_results=gbk;
      
      # 如果中文對(duì)不齊或亂碼
      charset gbk;
      

      面試題:delete和truncate的區(qū)別?

    2. DML:數(shù)據(jù)庫操作語言

      insert into 表名 values(1,'anfly',1.22,'1991-01-01');
      insert into 表名(id,name) vlaues(2,'bigfly');
      
      delete from 表名 [where 條件];
      truncate table 表名;
      update 表名 set name="",salery="" where 條件;
      
    3. DQL:數(shù)據(jù)庫查詢語言

      # 查
      select */name from 表名 [where id!><=1];
      # 并列、別名、修改數(shù)據(jù)
      select name as 姓名 , (math+chinese) as 數(shù)語和,(math10) as 數(shù)學(xué)加10 from 表名;
      # 條件合并
      select * from student where (math+english+chinese)>230;
      # 范圍:between a and b,a和b都包含
      select * from 表名 where math between 80 and 90;
      # 條件并列:and
      select * from 表名 where math > 80 and chinese > 90;
      # 匹配枚舉值:in
      select * from 表名 where math in(10,20,30);
      # 模糊查詢:like,"_"代表一個(gè)字符,"%"代表(0,∞)
      select * from 表名 where name like '_%';
      
      # 聚合函數(shù)
      max
      count
      min
      sum
      avg
      
      # 分組
      select sex,count(*) from 表名 group by sex;
      
      # 分頁查詢
      select * from 表名 limit 2,5;
      
      # 排序
      select * from 表名 order by math asc/desc limit2,5;
      
    4. DCL:數(shù)據(jù)庫控制語言

  6. 多表設(shè)計(jì)

    1. 一對(duì)一、一對(duì)多、多對(duì)多

      # 外鍵
      create table t(id int primary key,name varchar(100));
      create table s (id int primary key,name varchar(100));
      create table ts(t_id int,s_id int,constraint foreign key(t_id) references t(id),constraint foreign key(s_id) references s(id));
      
      # 李老師所有學(xué)生
      select * from s where id in(select s_id from ts where t_id=(select id from t where name = '李老師'));
      
      # 張三的所有老師
      select * from t where id in(select t_id from ts where s_id=(select id from s where name = '張三'));
      
    2. 多表聯(lián)查

      1. 交叉查詢

        # AB表
        select * from A,B;
        select * from A cross join B;
        
      2. 內(nèi)連接查詢

        select * from A inner join B on A.id=B.id;
        select * from A , B where A.id=B.id;
        
      3. 外連接查詢

        # 左外
        select * from A left join B on A.id=B.id;
        
        # 右外
        select * from A right join B on A.id=B.id;
        

        面試題:左外和右外的區(qū)別?

  7. Navicat

    1. 下載、安裝、破解

    2. 操作

      連接數(shù)據(jù)庫、建庫、刪庫、建表、刪表、插入數(shù)據(jù)、刪除數(shù)據(jù)、導(dǎo)出、導(dǎo)入

  8. 數(shù)據(jù)庫優(yōu)化

    索引優(yōu)化

  9. 數(shù)據(jù)庫性能檢測工具

    explain

  10. 數(shù)據(jù)庫視圖

?著作權(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)容