Question

In: Computer Science

subject DBA use mysql workbench and select my guitar shop database as default schema Problem8 Write...

subject DBA

use mysql workbench and select my guitar shop database as default schema

Problem8

Write a script that implements the following design in a database named my_web_db:

    users                                                       downloads                                                                 Products

*user_id INT                                         * download_id INT                                                   * product_id INT                     

*email_address VARCHAR(100)          * user_id INT                                                         * product_name VARCHAR(45)

*first_name VARCHAR(45)                  *download_date DATETIME

*last_name VARCHAR(45)                  * filename VARCHAR(50)

                                                               *product_id INT

Details

  • In the downloads table, the user_id and product_id columns are the foreign keys.
  • Include a statement to drop the database if it already exists.
  • Include statements to create and select the database.
  • Include any indexes that you think are necessary.
  • Specify the utf8 character set for all tables.
  • Specify the InnoDB storage engine for all tables.

Solution fill in the blanks :-

______DATABASE ____________ ;

CREATE DATABASE my_web_db ___________ ;

USE my_web_db;

_________ TABLE _______

    user_id       INT          PRIMARY _______ AUTO_INCREMENT,

    email_address VARCHAR(100) UNIQUE,

    first_name    VARCHAR(45) NOT NULL,

    last_name     VARCHAR(45) NOT NULL

) ___________ ;

__________ products (

    product_id   INT         ________ AUTO_INCREMENT,

    product_name VARCHAR(45) UNIQUE

__________

____________

    download_id   INT         PRIMARY KEY,

    ____________       INT         NOT NULL,

    download_date DATETIME    NOT NULL,

    filename      __________ NOT NULL,

    product_id    INT         NOT NULL,

    ___________ fk_downloads_users

_____________ KEY (user_id )

        REFERENCES users (user_id),

_______________

_______________ product_id)

        REFERENCES products _______________

) ENGINE = _________ ;

Solutions

Expert Solution

DROP DATABASE IF EXISTS my_web_db;/* statement to drop the database if it already exists.*/

CREATE DATABASE my_web_db; /* blank here should be empty as the syntax for creating the database is already given correct*/

USE my_web_db; /* selects the database my_web_db*/

CREATE TABLE IF NOT EXISTS users (

user_id    INT            PRIMARY KEY       AUTO_INCREMENT,
email_address    VARCHAR(100) UNIQUE,
first_name Varchar(45) not null,
last_name    VARCHAR(45) not null
) ENGINE = innoDB; /*Specify the InnoDB storage engine for all tables.*/

CREATE TABLE IF NOT EXISTS products(

product_id    INT PRIMARY KEY   AUTO_INCREMENT,
product_name    VARCHAR(45) UNIQUE
) ENGINE = innoDB; /*Specify the InnoDB storage engine for all tables.*/

CREATE TABLE IF NOT EXISTS downloads (

download_id   INT         PRIMARY KEY,

user_id INT NOT NULL,

download_date DATETIME    NOT NULL,

filename VARCHAR(45) NOT NULL,

product_id    INT   NOT NULL,

CONSTRAINT users_fk_downloads FOREIGN KEY (user_id)/*User_id is a foreign key*/

REFERENCES users (user_id),

CONSTRAINT products_fk_downloads

FOREIGN KEY (product_id) /*product_id is a foreign key/

REFERENCES products (product_id)

) ENGINE = innoDB; /*Specify the InnoDB storage engine for all tables.*/

ALTER SCHEMA `my_web_db` DEFAULT CHARACTER SET utf8 ;/*utf8 character set for all tables.*/


Related Solutions

Subject (DBA) use MYSQL workbench select my guitar shop database as default schema Question text Problem10...
Subject (DBA) use MYSQL workbench select my guitar shop database as default schema Question text Problem10 Write a script that implements the following design in a database named household_chores: Details Include a statement to drop the database if it already exists. Include statements to create and select the database. Include any indexes that you think are necessary. Specify the utf8 character set for all tables. Specify the InnoDB storage engine for all tables. Solution ______ DATABASE IF EXISTS ______ ;...
This refer to the “om” database (or Schema) that you will find in your MySQL Workbench...
This refer to the “om” database (or Schema) that you will find in your MySQL Workbench program if you have run the sample database install script. Please save all of your answers in one script (.sql) or type all your answers into Notepad++ and submit them as a single .sql file. Please test your SQL statements in Workbench 1.       Using an INNER JOIN, select the order_id, order_date, shipped_date, fname, and customer_phone from the orders and customers tables. The fname is a...
Part 2: Use MySQL Workbench to add a table to your database on the class server...
Part 2: Use MySQL Workbench to add a table to your database on the class server and name the table “Person”. Include these fields in the Person table: Field Name Description Data Type Sample Value LoginID User’s login name varchar(10) Bob FirstName User’s first name varchar(50) Bob LastName User’s last name varchar(50) Barker picUrl Filename of the user’s picture varchar(50) bob.gif Bio User’s biography varchar(255) Bob is the best! LoginID should be the Primary Key of the table. Add at...
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12....
In MySql, using Application MYSQL Workbench and the Chinook database, please answer the following: -- 12. SELECT the trackid, name and filesize (as shown in the bytes column) for all tracks that have a file size less than 2000000 and a GenreId of 1 or a file size less than 2000000 and a Genreid of 2 -- 13. Add a sort to the query from number 12 to sort by GenreID; -- 14. List all columns from the customer table...
Design and implement a relational database application of your choice using MS Workbench on MySQL a)...
Design and implement a relational database application of your choice using MS Workbench on MySQL a) Declare two relations (tables) using the SQL DDL. To each relation name, add the last 4 digits of your Student-ID. Each relation (table) should have at least 4 attributes. Insert data to both relations (tables); (15%) b) Based on your expected use of the database, choose some of the attributes of each relation as your primary keys (indexes). To each Primary Key name, add...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE...
Use MySQL server. First step: create and use database called EDU. Syntax: CREATE SCHEMA edu; USE edu; Create a script which will create the tables listed below: STUDENT(STUDENT_ID, STUDENT_NAME, MAJOR_ID, DOB, PHONE_NUMBER) MAJOR(MAJOR_ID, MAJOR_NAME) ENROLLMENT(STUDENT_ID, COURSE_ID, GRADE) COURSE(COURSE_ID, COURSE_NAME) RESPONSIBILITY(FACULTY_ID, COURSE_ID) TEACHER(FACULTY_ID, DEPT_ID, TEACHER_NAME) DEPARTMENT(DEPT_ID, DEPARTMENT_NAME) Start the script with a series of DROP statements so that as you correct mistakes you will start fresh each time. To avoid referential integrity errors, the table drops should be in the opposite...
Subject DataBase/MySQL What is wrong with this statement? SELECT vendor_id, (SELECT vendor_name FROM vendors), avg(invoice_total) FROM...
Subject DataBase/MySQL What is wrong with this statement? SELECT vendor_id, (SELECT vendor_name FROM vendors), avg(invoice_total) FROM invoices GROUP BY vendor_id; Select one: a. The subquery returns more than 1 row. b. You need a JOIN ON clause to pull from multiple tables. c. You cannot have a subquery in the SELECT statement. d. The result is a Cartesian Product. e. There is nothing wrong with this statement. What is wrong with this statement? SELECT vendor_name, avg(invoice_total) AS 'Invoice Total' FROM...
We use the WMCRM database and here is the summary of the database schema (where schema...
We use the WMCRM database and here is the summary of the database schema (where schema is used in its meaning of a summary of the database structure): VEHICLE (InventoryID, Model, VIN) SALESPERSON (NickName, LastName, FirstName, HireDate, WageRate, CommissionRate, OfficePhone, EmailAddress, InventoryID) CUSTOMER (CustomerID, LastName, FirstName, Address, City, State, ZIP, EmailAddress, NickName) PHONE_NUMBER (CustomerID, PhoneNumber, PhoneType) CONTACT(ContactID, CustomerID,ContactDate,ContactType,Remarks) Where InventoryID in SALESPERSON must exist in InventoryID in VEHICLE NickName in CUSTOMER must exist in NickName in SALESPERSON CustomerID in PHONE_NUMBER...
"How can I connect my hadoop database or mysql database server to my d3 visual?"
"How can I connect my hadoop database or mysql database server to my d3 visual?"
Subject - DataBase / MySQL * Which of the following is not correct about the statement...
Subject - DataBase / MySQL * Which of the following is not correct about the statement provided? SELECT Customer#, FirstName, LastName FROM Customers C JOIN Orders O ON C.Customer# = O.Customer# JOIN OrderItems OI ON O.Order# = OI.Order# JOIN Books B ON OI.ISBN = B.ISBN WHERE Category = 'Fitness' AND Category = 'Computers'; Select one: a. Joins the OrderItems table to the Books table using the field ISBN b. All of these are correct c. Joins the Customer table to...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT