8
I want to validate the proper handling of Foreign keys in table. Here are my two tables being created below. It is possible that a person may not have an address listed so I want it to be null. Otherwise I would like to reference a primary key from the address table and store it in the Person table as a foreign key. It is also possible that we may have an address object without a person.
Table for a Person:
CREATE TABLE Person
(
PersonID int IDENTITY PRIMARY KEY,
FName varchar(50) NULL,
MI char(1) NULL,
LName varchar(50) NULL,
AddressID int FOREIGN KEY REFERENCES Address(AddressID) NULL,
)
Table for Address:
CREATE TABLE Address
(
AddressID int IDENTITY PRIMARY KEY,
Street varchar(60) NULL,
City varchar(50) NULL,
State varchar(2) NULL,
Zip varchar(10)NULL,
Intersection1 varchar(60) NULL,
Intersection2 varchar(60) NULL,
)
Also Q2 I have never worked with triggers but I am assuming the way to handle an insert would be to use a stored procedure to insert the address first, get the primary key, then pass it to a stored procedure to insert into Person table?