您的位置:首页 > 其它

OCP-1Z0-051-2015-2题

2015-04-20 10:45 274 查看
QUESTION NO: 2
You need to design a student registration database that contains several tables storing academic   information.
The STUDENTS table stores information about a student. 
The STUDENT_GRADES table stores   information about the student's grades. Both of the tables have a column named STUDENT_ID.
The STUDENT_ID column in the STUDENTS table is a primary key.

You need to create a foreign key on the STUDENT_ID column of the STUDENT_GRADES table
that points to the STUDENT_ID column of the STUDENTS table. Which statement creates the
foreign key?

A. CREATE TABLE student_grades (student_id NUMBER(12),semester_end DATE, gpa
NUMBER(4,3), CONSTRAINT student_id_fk REFERENCES (student_id) FOREIGN KEY
students(student_id));

B. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa
NUMBER(4,3), student_id_fk FOREIGN KEY (student_id) REFERENCES students(student_id));

C. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa
NUMBER(4,3), CONSTRAINT FOREIGN KEY (student_id) REFERENCES students(student_id));

D. CREATE TABLE student_grades(student_id NUMBER(12),semester_end DATE, gpa
NUMBER(4,3), CONSTRAINT student_id_fk FOREIGN KEY (student_id) REFERENCES
students(student_id));
Answer: D
Explanation: 
表STUDENTS 存放学生信息 ,列STUDENT_ID  是主键
表STUDENT_GRADES 存放学生年纪信息,和表STUDENTS 都有一个列STUDENT_ID
需要了解创建表 建立外键约束的格式
如果需要命名
FOREIGN KEY 约束,以及为多个列定义 FOREIGN KEY 约束,请使用下面的 SQL 语法:

CREATE TABLE student_grades(student_id NUMBER(12),
semester_end DATE, gpa NUMBER(4,3),
  CONSTRAINT student_id_fk FOREIGN KEY (student_id) REFERENCE students(student_id));
如果需要命名 FOREIGN KEY 约束,以及添加 FOREIGN KEY 约束,请使用下面的 SQL 语法:

alter table student_grades
addCONSTRAINT
student_id_fk FOREIGN KEY (student_id) REFERENCE students(student_id));
如需撤销
FOREIGN KEY 约束,请使用下面的 SQL:

alter
table student_grades  drop CONSTRAINT
 student_id_fk 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: