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


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 query

Multy Relation Query(Join)

<

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值