Question

In: Computer Science

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 movies and a movie can have multiple actors.

  • Use the MySQL Database Instructions to create the three tables.
  • Once the three tables are completed, create a “join” statement that joins data from all three tables. Remember that field names used in more than one table (ASIN, ActorID) must be fully qualified (i.e., dvdtitle, ASIN).
  • The previous SQL query returns a separate record for each actor. Provide a way to group results from several records into a single row.

General guidelines for this interactive assignment:

  • String values in SQL statements are always enclosed within single quotes. ASIN and Title are both strings and require single quotes. For instance, your insert statement will look something like this:
    $sql = “Insert into dvdtitles (asin, title, price) VALUES (‘$asin’, ‘$title’, $price)”;
  • SQL debugging tip: check your SQL statement before you execute it. Put the following line of code immediately before the mysql_query($strSQL) statement.
  • When retrieving ASIN from the querystring, remember that ASIN is a string, not a number.
  • Explain in detail the process on how to group results from several records into a single row.

Solutions

Expert Solution

First create Database

syntax: create database database name;

create database movies_data;

then use database

use movies_data;

now create actor table

syntax : create table table_name (

col1 datatype,

col2 datatype,

col3 datatype,

...

);

  

create table actors(

ActorsID int auto_increment,

ActorsName varchar(100),

primary key(ActorsID)

);

actors table

create movie table   

syntax : create table table_name (

col1 datatype,

col2 datatype,

col3 datatype,

...

);

  create table movies(

MoviesID int auto_increment,

MovieName varchar(100),

primary key(MoviesID)

);

movies table

create role table   

  syntax : create table table_name (

col1 datatype,

col2 datatype,

col3 datatype,

...

);

create table role (

MoviesID int,

ActorsID int,

rolename varchar(100)

);

add foreign key constraints in role table

alter table role add foreign key(MoviesID) references movies(MoviesID);

alter table role add foreign key(ActorsID) references actors(ActorsID);

role table

insert data in tables string values in SQL statements are always enclosed within single quotes

actors table

movies table

role table

create inner-join statement that joins data from all three tables

select * from actors a inner join role r on a.ActorsID = r.ActorsID inner join movies m on m.MoviesID = r.MoviesID;

create left-join statement that joins data from all three tables

select * from actors a left join role r on a.ActorsID = r.ActorsID left join movies m on m.MoviesID = r.MoviesID;

create right-join statement that joins data from all three tables

select * from actors a right join role r on a.ActorsID = r.ActorsID right join movies m on m.MoviesID = r.MoviesID;

==Please Upvote==


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...
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 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.
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table as if it were being added to MySQL (please give explanations for each line of SQL code and a copy of the code as it would be entered into the query by itself: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer...
DBMS Create/Insert/Update SQL I need the create, insert, and update SQL statement for this table: Customer PK Customer ID Text Phone Number int name text address ID int email text FK vendor ID int Vendor is the name of the table the FK comes from.
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in...
Write CREATE TABLE and INSERT INTO statements in order to create and populate five tables in Oracle’s SQL*Plus.The information you need about the database ARE IN THE CHARTS BELOW. Each worksheet includes the following information about its associated table: ➢ Column names (for example, the jr_order table contains the orderID, customerID, orderDate, orderStatus, and orderShippedDate columns); ➢ Column data types (for example, orderID is INT, orderStatus is VARCHAR2(2), etc.); ➢ Column constraints, if any (for example, orderID in the jr_order...
SQL- Trigger I have two tables (below) I need to write a trigger that would delete...
SQL- Trigger I have two tables (below) I need to write a trigger that would delete everything for a pid from the Appt table if the pid is deleted from the patient table. Create table Appt(                 pid numeric Foreign Key references patient(pid),                 ptname varchar(50) Foreign Key references patient(name),                 dob date Foreign Key references patient(dob),                 dr varchar(20),                 appdate date,                 apptime time, ); and Create table Patient(                 pid numeric primary key,                 name varchar(50),                ...
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)...
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that...
Using the sample.sql script, create the sample database in MySQL. Submit the MySQL interactive screen that results. create database sample; use sample; create table customer (custno int auto_increment primary key, firstname varchar(20), middle varchar(20), lastname varchar(20), address varchar(60), telnum1 varchar(10), telnum2 varchar(10), telnum3 varchar(10), pin varchar(6), email varchar(30)); create table accttype (id int primary key, type varchar(10)); insert into accttype (id, type) values (1,'check'); insert into accttype (id, type) values (2,'save'); insert into accttype (id, type) values (3,'cd'); insert into...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the...
Write create table statements to create tables for the Exoproduct employees computers database depicted by the relational schema created in a mini case MC5 in chapter 3. Use insert into statements to insert no fewer than 2 and no more than 10 records per table.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT