3.7 Write an SQL CREATE TABLE statement to create the PET_OWNER table, with Owne
ID: 404675 • Letter: 3
Question
3.7 Write an SQL CREATE TABLE statement to create the PET_OWNER table, with OwnerID as a surrogate key. Justify your choices of column properties.
YOU CAN USE THIS AWNSER FOR 3.7 for 3.8-3.11
CREATE TABLE PET_OWNER (
OwnerID Integer Primary Key,
Name Char (50) Not Null,
Phone Char (12),
Email VarChar(100));
OwnerID is integer because it will be a surrogate key. (By the way, the means by which such keys are created varies from DBMS to DBMS, and is not discussed in this text.) Name is Char rather than varchar because we may search on it. Neither Phone nor Email are required
Explanation / Answer
CREATE TABLE PET_OWNER (
OwnerID Integer Primary Key,
Name Char (50) Not Null,
Phone Char (12),
Email VarChar(100));
create table PET_2 (
PetName char(20) not null,
PetType char(20),
PetBreed char(20),
PetDOB datetime not null,
OwnerID integer)
alter table PET_2
add constraint pk_pet2
primary key(PetName,PetDOB)
alter table PET_2
add constraint fk_pet2
foreign key (OwnerID)
references PET_OWNER(OwnerID)
all columns need not be null in the pet_2 table because we can uniquely identifiy each entry using petname and petdob togeteher.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.