ADEG in my opinion too...
A. A table can have only one primary key but multiple foreign keys --> For sure
B. A table can have only one primary key and one foreign key --> There is no such restrictions
C. The foreign key columns and parent table primary key columns must have the same names --> There is no such restriction.
D. It is possible for child rows that have a foreign key to remain in the child table at the time the parent row is deleted --> Can be achieved by disabling the FK constraint and re enabling with no validate clause after performing delete on parent table.
E. It is possible for child rows that have a foreign key to be deleted automatically from the child table at the time the parent row is deleted --> CASCADE option
F. Only the primary key can be defined at the column and table level --> No such restrictions
G. Primary key and foreign key constraints can be defined at both the column and table level --> True.
might correct A, B (can have), D, E, G
wrong C ("Must"), F (PK,FK, UQ, CK defined at column and table level. only not null in column level).
I vote ADEG
A - true; quote1: A table or view can have only one primary key., quote2: You can define multiple foreign keys in a table or view.
B - false; see quote2 in answer A
C - false; example, when names of FK columns and parent table columns are different: ALTER TABLE employees2 ADD CONSTRAINT fk_dept2 FOREIGN KEY (dept_id) REFERENCES departments2(id);
D - true; example: ALTER TABLE employees ADD CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES departments (id) ON DELETE SET NULL; perform INSERT(s) into employees with dept_id=17; DELETE FROM departments WHERE dept_id=17;
E - true; example: ALTER TABLE employees ADD CONSTRAINT fk_dept FOREIGN KEY (dept_id) REFERENCES departments (id) ON DELETE CASCADE;
F - false; Either primary key, unique constraint, foreign key or check contraints can be defined on both table and column levels.
G - true; see answer F
A - true; You can define multiple foreign keys in a table or view.
B - false; see A
C - false; a foreign key needn't be based on a primary key, it can be based on unique key, therefore its columns can have different names.
D - true; parent row can be deleted, but parrent column cannot be deleted (ORA-12992: cannot drop parent key column)
E - true; foreign key must be defined with ON DELETE CASCADE clause
F - false; not only primary key, but also other constraints can be defined both on table level and column level, e.g. CREATE TABLE a (b NUMBER UNIQUE) or CREATE TABLE a (b NUMBER, UNIQUE(b))
G - true; e.g. CREATE TABLE child (a number, b number REFERENCES parent(c)) or CREATE TABLE CHILD (a number, b number, FOREIGN KEY (parent_id) REFERENCES parent(c))
Source:
A,B,C Oracle documentation: Oracle Database, Release 19, SQL Language Reference, 8 Common SQL DDL Clauses, constraint
The correct answers are A,C,E,G
The D is not correct because for referential integrity it does not allow you to delete rows from the parent table and leave related rows in the child tables.
The E is correct because effectively when you delete rows from the parent table and you specify on delete cascade in the delete statement, it will delete the related rows in the child tables. If it is not specified, it does not allow deleting records from the parent table if you have related records.
A is correct. The only restriction is on the PK, a table can have only one. No restrictions exist on the number of FK's a table may have.
B is wrong. Tables may have many foreign keys in them, it all depends on the db's relational model.
C is wrong. The DB does not care about column names, only data type, size and contents of the PK and FK.
D is correct. The FK must be created with the ON DELETE SET NULL option. Without this option ORA-02292 will be raised when attempting to delete a row from the parent table that has child record.
E is correct. The FK must be created with ON DELETE CASCADE option. Without this option ORA-02292 will be raised when attempting to delete a row from the parent table that has child record.
F is wrong. The only constraint that has to be defined inline (column level) is NOT NULL.
G is correct. The only constraint that has to be defined inline (column level) is NOT NULL.
A voting comment increases the vote count for the chosen answer by one.
Upvoting a comment with a selected answer will also increase the vote count towards that answer by one.
So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.
danito
Highly Voted 4 years, 1 month agoEkos
3 years, 7 months agoNiciMilo
3 years, 11 months agonhsang
3 years, 11 months agoama
3 years, 10 months agoSimoneF
3 years, 6 months agorenzoku
3 years, 4 months agoavanand
Highly Voted 3 years, 10 months agoLrnsTgh
2 years, 10 months ago8hyehye8
Most Recent 3 months, 2 weeks agonautil2
8 months, 2 weeks agonautil2
8 months, 2 weeks agonautil2
8 months, 3 weeks agoOracle2020
11 months agozouve
11 months, 1 week agofthusa
1 year, 1 month agoryuah
2 years, 1 month agoalgerianphoenix
2 years, 2 months agoFranky_T
2 years, 2 months agocasfdsaf
2 years, 4 months agoryuah
2 years, 6 months agoLongHi
2 years, 7 months agoLongHi
2 years, 7 months agoLongHi
2 years, 7 months agoyou1234
4 years ago