Question: PROVIDE SQL CODE FOR THE CONSTRAINTS, PRIMARY KEY, BULK INSERT ETC. also how to load a file so we can bulk insert from them. Assignment
PROVIDE SQL CODE FOR THE CONSTRAINTS, PRIMARY KEY, BULK INSERT ETC. also how to load a file so we can bulk insert from them. Assignment
Use SQL to create the tables and constraints in your SQL Server database according to the
description below.
Your database should have the following tables, please read the Attributes and constraint part
carefully for primary and foreign keys.
You must use the exact names and domains specified. Marks will be deducted if you fail to do so
Tables
business businessid name, address, city, postalcode, stars, reviewcount
checkin checkinid businessid date
tip tipid userid businessid date, complimentcount
review reviewid userid businessid stars, useful, funny, cool, date
useryelp userid name, reviewcount, yelpingsince, useful, funny, cool, fans, averagestars
friendship userid friend
Attributes
You should use the domains listed below. Consider the described constraints and primary keys.
Table business
businessid: string primary key.
name: variablelength string not null.
address: variablelength string
city: variablelength string not null.
postalcode: variablelength string
stars: decimal in interval.
reviewcount: integer, default: nonnegative.
Table checkin
checkinid: integer, primary key.
businessid: string not null.
date: date and time, not null, default: current date.
Table tip
tipid: integer, primary key.
userid: string not null.
businessid: string not null.
date: date and time, not null, default: current date.
complimentcount: integer, default: nonnegative.
Table friendship
userid: string primary key
friend: string primary key
Table review
reviewid: string primary key.
userid: string not null.
businessid: string not null.
stars: integer, not null, between and
useful: integer, default: nonnegative.
funny: integer, default: nonnegative.
cool: integer, default: nonnegative.
date: date and time, default: current date.
Table useryelp
userid: string primary key.
name: variablelength string not null.
reviewcount: integer, default nonnegative.
yelpingsince: date and time, not null, default: current date.
useful: integer, default: nonnegative.
funny: integer, default: nonnegative.
cool: integer, default: nonnegative.
fans: integer, default: nonnegative.
averagestars: decimal in interval. Note: Consider a fixedlength string where not specified otherwise.
Constraints
Your database should enforce the primary key constraints noted above.
The following foreign key constraints also need to be enforced:
checkin.businessid references business.businessid
tip.businessid references business.businessid
tip.userid references useryelp.userid
review.businessid references business.businessid
review.userid references useryelp.userid
friendship.userid references useryelp.userid
friendship.friend references useryelp.userid
The response to the violation of foreign keys constraints should be to not allow deletion or
update of referenced records.
Assignment
Insert the sample data provided on CourSys into the tables that you have created. The zip file
assignmentzip posted on CourSys under Datasets, contains one file for each table.
Use one of the following two options:
Command prompt: bcp
bcp "dbName.dbo.tableName" in "ifile" S SQLserver b m T c F
TSQL: bulk insert
Example:
"BULK INSERT dbo.business FROM d:userdatabusinesscsv WITH fieldterminator
rowterminator
firstrow
Remember you will need to insert data in a sensible order that respects the foreign key
constraints. Report the order in which you execute the statements.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
