Question

In: Computer Science

Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category,...

Write the SQL DDL to create the following 5 tables for an App store: Publisher, Category, App, AppVersion, AppVersionReview:

  1. A Publisher table where each publisher is identified by an integer id and has a name (up to 40 characters). (1 mark)

  2. A Category table where each category has an id (integer), a name (up to 50 characters), and a parentId to identify its parent category. The parentId should be a foreign key to the Category table. (1.5 marks)

  3. An App table storing each app that is identified by a field called id that is an integer. Other attributes include name (string up to 40 characters), publisherId (integer), categoryId (integer), and description (string up to 255 characters). Make all foreign keys set to null on delete and no action (generate error) on update.

  4. A AppVersion table that stores each version of the app. The primary key is the appId and version (exactly 10 characters). Each release has a releaseDate (DATETIME), an integer rating, a price (up to 10 digits with 2 decimals), and a description (up to 500 characters). Make all foreign keys set to perform cascade on delete and cascade on update.

  5. A AppVersionReview table that stores ratings for each application version. The primary key is the appId, version, and reviewer (exactly 20 characters). There is also a reviewDate (DATETIME), rating (int), and review (up to 1000 characters). Make all foreign keys set to cascade on both update and delete. A value for the reviewDate field is always required.

Solutions

Expert Solution

Solution:

Syntax for creating a table in database is

create table tablename(column datatype, column datatype,....................)

1) create table Publisher(publisherId int, name varchar(40))

2) create table Category(categoryId int, name varchar(50), parentId int, Foreign Key(parentId))

3) create table App(Id int, name varchar(40), publisherId int, categoryId int, description varchar(255),

Constraint fk_ap_id

Foreign Key(publisherId, categoryId)

References Publisher(publisherId), Category(categoryId)

On Delete set NULL [ On Update { No Action } ] )

4) create table AppVersion(appId int Primary Key, version varchar(10), releaseDate Date, rating int, price decimal(10, 2), description varchar(500),

Constraint fk_appver_id

Foreign Key(appId)

References App(id)

On Delete set NULL [ On Update { Cascade } ] )

5) create table AppVersionReview(appId int Primary Key, version varchar(10), reviewer varchar(20), reviewDate Date NOT NULL, rating int, review varchar(1000),

Constraint fk_appver_rev_id

Foreign Key(appId)

References App(id)

On Delete set NULL [ On Update { Cascade } ] )


Related Solutions

Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The...
Create three MySQL database tables and write SQL scripts to read, insert, and delete data. The first database table will contain the names of at least four movies. The second table will be a list of actors who appear in the movies. The third table will be an associative table that describes the relationship between the actors and their movies (which actors appear in which movies). Actors and movies have a “many-to-many relationship,” meaning an actor can be in multiple...
SQL code Create entities (tables) to represent the following ternary relationship. Note that we are not...
SQL code Create entities (tables) to represent the following ternary relationship. Note that we are not storing all the required information in these entities to simplify it. The underlined attributes are the primary keys. Don’t forget to set the constraints for primary and foreign keys: •A student entity ( bannerId, first name, last name, date of birth) •A course entity ( crnNumber, course name, # of credits) •An examination entity ( examId, exam_type, exam_date). (exam types can be “Midterm”, “Final”,...
Develop the SQL scripts that will create the tables and enforce all the appropriate constraints •...
Develop the SQL scripts that will create the tables and enforce all the appropriate constraints • Develop sample SQL scripts that will insert the data to the database (one row in each table) • Convert at least 2 entities to MongoDB Collections. Write the scripts that will Create the collection(s)
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve...
Using the HotelDB tables, provide the following result as a screen image. WRITE SQL to retrieve rows from any hotel with Family room types and price less than $150. use hoteldb; CREATE TABLE HOTEL ( hotelNo numeric primary key , name varchar(40) , address varchar(40) , city varchar(200) ); CREATE TABLE ROOM ( roomNo numeric Primary Key , hotelNo numeric References HOTEL , type varchar(20) , price dec(9,2) ); CREATE TABLE GUEST ( guestNo numeric primary key , name varchar(40)...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table:...
Homework: Populate Sales Order tables. Write SQL to : 1. insert 5 records in each table: Market, Region, ProductFamily, Manager (all Managers must have different % commissions, Commission is an attribute of the Manger). 2. Insert 5 records in Agent using all Managers 3. Insert 15 records in Product using  all ProductFamily 4. Insert 15 records in Customer using various Regions and Markets 5. Insert 50 records in SalesOrder using various Customers, Products, Agents Notes : ALL the Names ( Description)...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns...
Create a table in SQL with foreign key reference: 1.Create the three tables without any columns 2.Alter the tables to add the columns 3.Alter the tables to create the primary and foreign keys
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based...
Using your downloaded DBMS (MS SQL Server), create a new database. Create the database tables based on your entities defining The attributes within each table The primary and foreign keys within each table *****Show your database tables, tables attributes, primary and foreign keys***** Do not forget to check the lesson slides and videos that show you how to convert an ER/EER into a database schema, and how to create a database and tables using MS SQL Server.
. Please write the SQL statements required to create the following relations, including appropriate versions of...
. Please write the SQL statements required to create the following relations, including appropriate versions of all primary and foreign key integrity constraints. (10 points) Books (isbn:CHAR(10), title: CHAR(20), author: CHAR(80), qty_in_stock: INTEGER, price: REAL, year_published: INTEGER) Customers (cid:INTEGER, cname: CHAR(80), address: CHAR(200)) Orders (ordernum:INTEGER, cid:INTEGER, order_date: DATE, cardnum:CHAR(16)) Orderlists (ordernum:INTEGER, isbn:CHAR(10), qty:INTEGER, ship_date:DATE)
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier...
Using Triggers (5 pts.) Execute the following SQL to create the customer_audit table in the premier schema. CREATE TABLE IF NOT EXISTS customer_audit ( customer_num CHAR(3) NOT NULL,   customer_name VARCHAR(35) NOT NULL, street VARCHAR(15), city VARCHAR(15), state CHAR(2), zip CHAR(5), credit_limit DECIMAL(8,2), date_changed DATETIME NOT NULL, changed_by VARCHAR(45) NOT NULL); Notice that the audit table does not have a primary key defined. Explain why this might be acceptable. Based on the current attributes in the customer_audit table, suggest a possible...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT