日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > windows >内容正文

windows

数据库系统概念总结:第三章 SQL

發布時間:2025/3/19 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据库系统概念总结:第三章 SQL 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

周末無事水文章,期末備考的總結資料

第三章 SQL

3.1 SQL查詢語言概況

3.2 SQL數據定義

3.2.1 基本類型

  • char(n):固定長度n的字符串(長度不夠自動補空格)
  • varchar(n):可變長度的最大長度為n的字符串
  • int:整型
  • smallint:小整型
  • numeric(p,d):定點數
  • real,double precision:浮點數與雙精度浮點數
  • float(n):精度至少為n的浮點數

3.2.2 基本定義模式

  • 建表
  • 修改/刪除表

    – delete from r,意思是刪除表中所有的內容

3.3 SQL查詢的基本結構

3.3.1 單關系查詢

  • 強行刪除重復:select distinct dept_name from instructor;
  • 顯示指明不去除重復:select all dept_name from instructor;

3.3.2 多關系查詢

select A1, A2, ..., An from r1, r2, ..., rm where P;

3.3.3 自然連接

select name, title from instructor natural join teaches natural join course;

3.4 附加的基本運算

3.4.1 更名運算

  • 變量名:select ID, name, salary/12 as monthly_salary from instructor;
  • 表名:select distinct T. name from instructor as T, instructor as S where T.salary > S.salary and S.dept_name = 'Comp. Sci.';

3.4.2 字符串運算

  • 包含子串:select name from instructor where name like '%in%' ;

3.4.3 select子句紅的屬性說明

3.4.4 排序元組的顯示次序

select distinct name from instructor order by name;

3.4.5 where子句謂詞

3.5 集合運算

3.5.1 并運算

select course_id from section where semester = 'Fall' and year = 2009 union select course_id from section where semester = 'Spring' and year = 2010;

3.5.2 交運算

select course_id from section where semester = 'Fall' and year = 2009 intersect select course_id from section where semester = 'Spring' and year = 2010;

3.5.3 查運算

select course_id from section where semester = 'Fall' and year = 2009except select course_id from section where semester = 'Spring' and year = 2010;

3.6 空值

3.7 聚集(Aggregate)函數

3.7.1 基本聚集

  • avg: 平均值
  • min: 最小值
  • max: 最大值
  • sum: 值的求和
  • count: 值的數量

3.7.2 分組聚集

  • group by語法:select dept_name, avg (salary) from instructor group by dept_name;

3.7.3 having子句

  • 分組限定的條件:select dept_name, avg (salary) from instructor group by dept_name having avg (salary) > 42000;

3.7.4 對空值和布爾值的聚集

3.8 嵌套子查詢

3.8.1 集合成員資格

select distinct course_id from section where semester = 'Fall' and year= 2009 and course_id in (select course_idfrom sectionwhere semester = 'Spring' and year= 2010);

3.8.2 集合的比較

select name from instructor where salary > some (select salaryrom instructorwhere dept_name = 'Biology');
  • 注:其中some表示一些,也可被all替代,意思為全部

3.8.3 空關系測試

select course_id from section as S where semester = ’Fall’ and year = 2009 and exists (select *from section as Twhere semester = ’Spring’ and year= 2010 and S.course_id = T.course_id);
  • 注:子查詢為非空時返回true值

3.8.4 重復元組存在性測試

select T.course_id from course as T where unique (select R.course_idfrom section as Rwhere T.course_id= R.course_id and R.year = 2009);
  • 注:子查詢結果中沒有重復的元組,unique結構將返回true值

3.9 數據庫的修改

3.9.1 刪除

delete from r where P;

3.9.2 插入

insert into course values ('CS-437', 'Database Systems', 'Comp. Sci.', 4); insert into course (course_id, title, dept_name, credits) values ('CS-437', 'Database Systems', 'Comp. Sci.', 4);

3.9.3 更新

update instructor set salary = salary * 1.03 where salary > 100000;

總結

以上是生活随笔為你收集整理的数据库系统概念总结:第三章 SQL的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。