2011年自考《中国行政史》复习资料第十三章 - 图文 联系客服

发布时间 : 星期五 文章2011年自考《中国行政史》复习资料第十三章 - 图文更新完毕开始阅读

B、自然连接: 在连接的目标列中相同名的列只保留一个

Select publishers.pub_id publishers.pub_name, publishers.state, authors.* From publishers, authors where publishers.city=authors.city

3.3 子查询

A、表达式子查询

Select au_lname, au_fname from authors where city= (select city from publishers where pub_name=\

可以使用一切大小比较操作符;在操作符和子查询之间可以使用All 或any。 B、定谓词子查询

Select pub_name from publishers from publishers Where pub_id in

(select pub_id from titles where type='abcde') C、相关查询

相关查询即嵌套查询依赖于外部父查询的值,嵌套查询要重复执行若干次。 Select distinct t1.type from titles t1

Where t1.type in ( select t2.type from titles t2 where t1.pub_id!=t2.pub_id)

3.4 集函数、分组与排序

A、对查询结果进行聚集处理

聚集函数: Sum([all|distinct] expression),avg([all|distinct] exoression) , Count([all|distinct]expression), count(*), max(expression), min(expression) Select count(*) from titles B、用Group by 和 having 子句对查询结果分组

Select type ,avg(advance), sum(total_sales) from titles group by type Select type from titles group by type having count(*) >1 Having 类似于where , 但where 不能用聚集函数。 C、用Order by 对查询结果进行排序

21

Select type ,avg(price) from titles group by type order by avg(price) D、Compute 子句

完成基于每一组中的值的聚集运算,聚集值作为一个新行出现在查询结果中。 Select type ,price advance from titles order by type compute sum(price), sum(advance) by type

22

第4章 数据库、数据库对象的增、删、改

4.1 数据库

4.2 表

打开数据库 Use tele114

创建数据库。拥有创建数据库权利的用户可以创建自己的数据库。 CREATE DATABASE tele114

ON tele114_def01=10,tele114_run01=200,tele114_idx01=200 LOG ON tele114_log01=80 删除数据库

Drop database tele114 修改数据库

Alter database tele114 on tele114_run02=100, tele114_idx02=100

建表

create table spec_code (

No tinyint not null, /*特编号(0--99)*/ Name varchar(50) null, /*名称*/ Addr varchar(50) null, /*地址*/ Tel varchar(8) null, /*电话号码*/ StaffNo varchar(4) not null /*录入员工号*/ )

on segrun /*将表放在segrun段上*/ 删除表

23

Drop tabel tele114_1th

修改表,在表中增加新的列(用这个命令增加的列必须允许null值) Alter table friends_etc add country varchar(20 ) null 表级或列级约束

Create table my_publishers (pub_id char(4), Pub_name carchar(40). Constraint my_chk_constraint

Check (pub_id in ('1389','0736','0877')) Or (pub_name not like 'bad news books')) 指定默认值

Create table ny_titles (title_id char(6t), Title varchar(80), Price money default null, Total_sales int default (0)) 指定Unique 和primary key 约束

Primary key 不允许空值,常用来产生唯一的聚集索引,unique 允许空值,常用来产生唯一的非聚集索引 Create table my_sales (stor_id char(4), Ord_num varchar(20), Date datetime,

Unique clustered(stor_id,ord_num))

4.3 索引

建立索引

create unique clustered code_1th(Code1,Name,UnitNo1,Used)

index

code1thidx1

on

24