OCP-1Z0-新051-61题版本-2
2013-12-28 18:05
323 查看
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
答案解析:
参考:http://docs.oracle.com/cd/E11882_01/server.112/e41084/clauses002.htm#SQLRF52238
Foreign Key Constraint Example The following statement creates the
of the
CREATE TABLE dept_20
(employee_id NUMBER(4),
last_name VARCHAR2(10),
job_id VARCHAR2(9),
manager_id NUMBER(4),
hire_date DATE,
salary NUMBER(7,2),
commission_pct NUMBER(7,2),
department_id CONSTRAINT fk_deptno
REFERENCES departments(department_id) );
The constraint
they are not assigned to any department. To ensure that all employees are assigned to a department, you could create a
Before you define and enable this constraint, you must define and enable a constraint that designates the
The foreign key constraint definition does not use the
automatically assigns to this column the data type of the referenced key.
The constraint definition identifies both the parent table and the columns of the referenced key. Because the referenced key is the primary key of the parent table, the referenced key column names are optional.
Alternatively, you can define this foreign key constraint out of line:
CREATE TABLE dept_20
(employee_id NUMBER(4),
last_name VARCHAR2(10),
job_id VARCHAR2(9),
manager_id NUMBER(4),
hire_date DATE,
salary NUMBER(7,2),
commission_pct NUMBER(7,2),
department_id,
CONSTRAINT fk_deptno
FOREIGN KEY (department_id)
REFERENCES departments(department_id) );
The foreign key definitions in both variations of this statement omit the
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
答案解析:
参考:http://docs.oracle.com/cd/E11882_01/server.112/e41084/clauses002.htm#SQLRF52238
Foreign Key Constraint Example The following statement creates the
dept_20table and defines and enables a foreign key on the
department_idcolumn that references the primary key on the
department_idcolumn
of the
departmentstable:
CREATE TABLE dept_20
(employee_id NUMBER(4),
last_name VARCHAR2(10),
job_id VARCHAR2(9),
manager_id NUMBER(4),
hire_date DATE,
salary NUMBER(7,2),
commission_pct NUMBER(7,2),
department_id CONSTRAINT fk_deptno
REFERENCES departments(department_id) );
The constraint
fk_deptnoensures that all departments given for employees in the
dept_20table are present in the
departmentstable. However, employees can have null department numbers, meaning
they are not assigned to any department. To ensure that all employees are assigned to a department, you could create a
NOT
NULLconstraint on the
department_idcolumn in the
dept_20table in addition to the
REFERENCESconstraint.
Before you define and enable this constraint, you must define and enable a constraint that designates the
department_idcolumn of the
departmentstable as a primary or unique key.
The foreign key constraint definition does not use the
FOREIGN
KEYclause, because the constraint is defined inline. The data type of the
department_idcolumn is not needed, because Oracle
automatically assigns to this column the data type of the referenced key.
The constraint definition identifies both the parent table and the columns of the referenced key. Because the referenced key is the primary key of the parent table, the referenced key column names are optional.
Alternatively, you can define this foreign key constraint out of line:
CREATE TABLE dept_20
(employee_id NUMBER(4),
last_name VARCHAR2(10),
job_id VARCHAR2(9),
manager_id NUMBER(4),
hire_date DATE,
salary NUMBER(7,2),
commission_pct NUMBER(7,2),
department_id,
CONSTRAINT fk_deptno
FOREIGN KEY (department_id)
REFERENCES departments(department_id) );
The foreign key definitions in both variations of this statement omit the
ON
DELETEclause, causing Oracle to prevent the deletion of a department if any employee works in that department.
相关文章推荐
- OCP-1Z0-新051-61题版本-16
- OCP-1Z0-新051-61题版本-28
- OCP-1Z0-新051-61题版本-46
- OCP-1Z0-新051-61题版本-1
- OCP-1Z0-新051-61题版本-17
- OCP-1Z0-新051-61题版本-29
- OCP-1Z0-新051-61题版本-47
- OCP-1Z0-新051-61题版本-3
- OCP-1Z0-新051-61题版本-18
- OCP-1Z0-新051-61题版本-30
- OCP-1Z0-新051-61题版本-48
- OCP-1Z0-新051-61题版本-4
- OCP-1Z0-新051-61题版本-19
- OCP-1Z0-新051-61题版本-31
- OCP-1Z0-新051-61题版本-49
- OCP-1Z0-新051-61题版本-5
- OCP-1Z0-新051-61题版本-20
- OCP-1Z0-新051-61题版本-32
- OCP-1Z0-新051-61题版本-50
- OCP-1Z0-新051-61题版本-6