Complete the code to create a table with a primary key.
CREATE TABLE Person (PersonID [1] PRIMARY KEY, Name VARCHAR(100));
The column PersonID should be of type INT to store integer IDs.
Complete the code to create a table with a foreign key referencing PersonID.
CREATE TABLE Passport (PassportID INT PRIMARY KEY, PersonID INT [1] NULL, FOREIGN KEY (PersonID) REFERENCES Person(PersonID));The PersonID column should be NOT NULL to ensure every passport is linked to a person.
Fix the error in the code to enforce one-to-one relationship by adding a constraint.
ALTER TABLE Passport ADD CONSTRAINT [1] UNIQUE (PersonID);The UNIQUE constraint on PersonID ensures one-to-one relationship by preventing duplicates.
Fill both blanks to create a one-to-one relationship where PassportID is also the foreign key.
CREATE TABLE Passport (PassportID INT [1] PRIMARY KEY, FOREIGN KEY (PassportID) [2] REFERENCES Person(PersonID));
PassportID must be NOT NULL and the foreign key uses ON DELETE CASCADE to remove passports if the person is deleted.
Fill all three blanks to insert a new person and their passport ensuring the one-to-one relationship.
INSERT INTO Person (PersonID, Name) VALUES ([1], 'Alice'); INSERT INTO Passport (PassportID, PersonID) VALUES ([2], [3]);
PersonID is 1, PassportID is 1001, and Passport.PersonID matches PersonID 1 to keep one-to-one link.