Which statement would you use to add a primary key constraint?
| Question ID 8160 | Which statement would you use to add a primary key constraint to the patient table using the id_number column immediately enabling the constraint? |
|---|---|
| Option D | ALTER TABLE patient MODIFY(id_number CONSTRAINT pat_id_pk PRIMARY KEY); |
| Correct Answer | B |
Which SQL statement defines the foreign key constraint?
CREATE TABLE EMP (empno NUMBER (4),ename VARCHAR2(35),deptno NUMBER(7,2) FOREIGN KEYCONSTRAINT emp deptno fk REFERENCES dept (deptno));Answer: BExplanation:This statement provides correct syntax to define the FOREIGN KEY constraint on theDEPTNO column of the EMP table.
When do you get error cannot add FOREIGN KEY constraint?
ERROR 1215 (HY000): Cannot add foreign key constraint It is also worth noting that you get this error when the type of the column that is a foreign key in another able doesn’t explicitly match the column in the correct table.
Why is MySQL error 1215 not generating foreign key?
So, if a file asks for a foreign key constraint referring to a key which will be, but not yet, generated in a latter file, the Error 1215 is fired. In such case, what you have to do is adjust the order of migration files generation.
When do you get an error 1215 in SQL?
ERROR 1215 (HY000): Cannot add foreign key constraint. It is also worth noting that you get this error when the type of the column that is a foreign key in another able doesn’t explicitly match the column in the correct table. For example: alter table schoolPersons add index FKEF5AB5E532C8FBFA
Why is MySQL error 1215 not match for constraint?
Cannot find an index in the referenced table where the referenced columns appear as the first columns, or column types in the table and the referenced table do not match for constraint. Error 1215 is an annoying one. Explosion Pill’s answer covers the basics.