In: Computer Science
You should try this code in Microsoft SQL Server to get the practice of using the command line and getting syntax errors. You can submit to me your sql files or just copy and paste of your code in a word document. I may try to run it, so make sure it is error free. Or you can show screen shots of code running.
hint: IDENTITY (1, 1) is syntax for surrogate key.
PET_OWNER (OwnerID, OwnerLastName, OwnerFirstName, OwnerPhone, OwnerEmail)
You can try inserting some data into your tables too!
hint: IDENTITY (1, 1) syntax for surrrogate key..
PET (PetID, PetName, PetType, PetBreed, PetDOB, OwnerID)
You don’t need to create referential integrity constraint on OwnerID in PET table.
Question1:
Write SQL CREATE Table statement to create the following
table with Owner ID as a surrogate key.
Table:
PET_OWNER (OwnerID, OwnerLastName, OwnerFirstName, OwnerPhone, OwnerEmail)
Crate statement:
CREATE TABLE PET_OWNER(
OwnerID INT IDENTITY(1,1),
OwnerLastName varchar(255),
OwnerFirstName varchar(255),
OwnerPhone varchar(25),
OwnerEmail varchar(255)
);
Question-2:
Write SQL CREATE Table statement to create the following table with Pet ID as a surrogate key. Pet ID is a surrogate key (starts at 1 and increments by 1)
Table:
PET (PetID, PetName, PetType, PetBreed, PetDOB, OwnerID)
Note: You don’t need to create referential integrity constraint on OwnerID in PET table.
Crate statement:
CREATE TABLE PET(
PetID INT IDENTITY(1,1),
PetName varchar(255),
PetType varchar(255),
PetBreed varchar(25),
PetDOB DATE
);
3)
Now create the referential integrity constraint on OwnerID in PET.
You can use ALTER TABLE command.
ALTER TABLE PET ADD FOREIGN KEY(OwnerID) REFRENCES OWNER(OwnerID);