数据库期末复习之初级SQL(双语)

本文介绍了SQL的基础知识,包括数据定义语言(DDL)如Create, Drop Table, Alter Table,数据操纵语言(DML)如Deletion, Insertion, Updates。重点讲解了基本查询结构,如Inner Join, Outer Join,以及聚合函数的使用。此外,还涵盖了子查询的多种应用,如集合成员资格测试和比较,以及如何处理NULL值。" 104977160,8225337,洛谷P3870开关:线段树入门解析,"['数据结构', '算法', '线段树', '竞赛编程', '洛谷']

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


Data Definition Language

Create

create table r ( A 1 D 1,
		 A 2 D 2,
		  ......, 
		  A n D n , 
		  (integrity-constraint1), 
		  ......,
		   (integrity-constraintk) )
# r is the name of the relation 
# each Ai is an attribute name in the schema of relation r 
# Di is the data type of values in the domain of attribute Ai

Create Table Extensions
Create Table Extensions

Drop Table

Alter Table Constructs

alter table r add A D
alter table r drop A     

Data Manipulation Language

Deletion

delete from r where P; 

Insertion

insert into course values ( ‘C5-437' , 'Database System' , 'Comp. sci. ’ ,4) ; 
insert into student 
	select ID, name, dept_name, 0 
	from instructor;

Updates

update instructor 
	set salary = salary * 1.03 
	where salary > 100000;
update student S 
set tot_cred = (select sum(credits) 
		from takes natural join course 
		where S.ID= takes.ID and takes.grade <> 'F' and 
		takes.grade is not null); 

Basic Query Structure

Typical SQL query

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

The select Clause
The select clause list the attributes desired in the result of a query

  • distinct:elimination of duplicates(去重)
  • all:duplicates not be removed(default)

The where Clause
The where clause specifies conditions that the result must satisfy

The from Clause
The from clause lists the relations involved in the qu

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值