数据库作业2

本文讨论了数据库中关于主键和外键的概念。在导师关系中,由于一个学生可能有多个导师,s_id不再适合作为主键,主键应为i_id和s_id组合。在银行数据库场景下,提到了各个表的合适主键和外键选择。此外,解释了为何数据库中会存在空值,以及过程性与非过程性语言在数据库查询中的优缺点。
摘要由CSDN通过智能技术生成

1.Consider the advisor relation shown in Figure 2.9, with s_id as the primary key of advisor. Suppose a student can have more than one advisor. Then, would s_id still be a primary key of the advisor relation? If not, what should the primary key of advisor be?

AnswerNow s_ ID is not the primary key of the advisor relationship. Because a student can have multiple tutors, a student may be taught by multiple tutors. Advisor cannot be used to distinguish students. The primary key should be i_ id and s_ id;

(译:此时s_id不是导师关系的主键字段,因为一个学生可以有多个导师,所以一个学生可能会被多个导师教导,用导师无法区分学生,主码应该是i_id s_id。)

2. Consider the bank database of Figure 2.11.

a. What are the appropriate primary keys?

b. Given your choice of primary keys, identify appropriate foreign keys.

a.

Answer schema     primary key

          Branch     branch_name

          Customer   ID

          Loan       loan_number

          Borrower   ID/loan_number

          Account    account_number

          Depositor   ID/account_number

b.

Answer: I. For loan: branch_name referencing branch.

        II. For borrower:  Attribute ID referencing customer and loan_number referencing loan.

        III. For account: branch_name  referencing branch.

        IV. For depositor:  Attribute ID referencing customer and account_number referencing account.

 

 (译文略)

      

3. List two reasons why null values might be introduced into the database.

AnswerWhen the exact value is unknown or does not exist, null values may be introduced.

(译:当确切值未知或不存在时,可能会引入空值。)

4. Discuss the relative merits of procedural and nonprocedural languages.

Answer: Nonprocedural languages greatly simplify the specification of queries(at least, the types of queries they are designed to handle).They free the user from having to worry about how the query is to be evaluated; not only does this reduce programming effort, but in fact in most situations the query optimizer can do a much better task of choosing the best way to evaluate a query than a programmer working by trial and error.

On the other hand, procedural languages are far more powerful in terms of what computations they can perfom. some tasks can either not be done using nonprocedural languages, or are very hard to express using nonprocedural languages,  or execute very inefficiently if specified in a nonprocedural manner.

(译:非过程语言极大地简化了查询的规范(至少是它们设计用来处理的查询类型)。它们让用户不用担心如何评估查询;这不仅减少了编程工作量,而且事实上,在大多数情况下,查询优化器在选择最佳方式评估查询方面比程序员通过试错来完成的任务要好得多。

另一方面,过程语言在计算能力方面要强大得多。有些任务要么不能用非程序语言完成,要么很难用非程序语言表达,要么以非程序方式指定时执行效率很低。)

你以为?真的C!

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值