Question

In: Computer Science

Using MYSQL in terminal, create the tables for your above designed relational schema and populate your...

Using MYSQL in terminal, create the tables for your above designed relational schema and populate your tables with appropriate data. All except time slot and the relationship it participates in. Use the names for the tables and attributes from the ER schema. Use ON DELETE CASCADE for foreign keys.

Each basic table (corresponding to an entity in the ER schema developed for Part 1) should have 5-10 rows. Campus can have just 2. Building should have at least 6. At least 1 building name (Laurel) should be in both campuses.

The remaining tables should have at least 10 rows. Make sure that your tables are in compliance with the participation constraints.

Show the following:

·create table commands that you used

·any commands that you used to insert or load into the tables (in the order in which they were performed- order matters!)

·content of you table as a result as a select * from (each table)

-----------------------

Here is the schema:

building(pk(building_name), num_floors, num_classrooms)
campus(pk(campus_name), state_name, school_name)
classroom(pk(room_number), capacity)
course(pk(course_id), title, credits)
instructor(pk(iid), salary, inst_name)
department(pk(dept_name), budget)
student(pk(sid), stud_name, tot_cred)
time_slot(pk(time_slot_id), {day, start_time, end_time})
section(pk(section_id), pk(semester), pk(year))

has(pk(dept_name, building_name), fk(dept_name) ref department(dept_name), fk(building_name) ref building(building_name))
course_dept(pk(dept_name, course_id), fk(dept_name) ref department(dept_name), fk(course_id) ref course(course_id))
inst_dept(pk(dept_name, iid), fk(dept_name) ref department(dept_name), fk(iid) ref instructor(iid))
mentors(pk(iid, sid), fk(iid) ref instructor(iid), fk(sid) ref student(sid))
stud_dept(pk(dept_name, sid), fk(dept_name) ref department(dept_name), fk(sid) ref student(sid))
takes(pk(sid, section_id), grade, fk(sid) ref student(sid), fk(section_id) ref section(section_id))
sec_time_slot(pk(time_slot_id), pk(section_id, semester, year), fk(time_slot_id) ref time_slot(time_slot_id), fk(section_id, semester, year) ref section(section_id, semester, year))
sec_class(pk(section_id, room_number), fk(section_id) ref section, fk(room_number) ref classroom(room_number))
teaches(pk(iid), pk(section_id, semester, year), fk(iid) ref instructor(iid), fk(section_id, semester, year) ref (section(section_id, semester, year)))
prereq(pk(course_id), fk(course_id) ref course)

Solutions

Expert Solution

To create a table for building i.e. building(pk(building_name),num_floors,num_classrooms) following query is used :-

CREATE TABLE building(

building_name varchar(25) NOT NULL PRIMARY KEY,

num_floors int(20),

num_classrooms int(100)

);

Now to insert values in the above table created i.e. building table following query is used :-

INSERT INTO building VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM building;

To create a table for campus i.e. campus(pk(campus_name,state_name,school_name) following query is used :-

CREATE TABLE campus(

campus_name varchar(30) NOT NULL PRIMARY KEY,

state_name varchar(40),

school_name varchar(40)

);

Now to insert values in the above table created i.e. campus table following query is used :-

INSERT INTO campus VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM campus;

To create a table for classroom i.e. classroom(pk(room_number), capacity) following query is used :-

CREATE TABLE classroom(

room_number int(15) NOT NULL PRIMARY KEY,

capacity int(100)

);

Now to insert values in the above table created i.e. classroom table following query is used :-

INSERT INTO classroom VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM classroom;

To create a table for course i.e. course(pk(course_id), title, credits) following query is used :-

CREATE TABLE course(

course_id varchar(50) NOT NULL PRIMARY KEY,

title varchar(40),

credits varchar(40)

);

Now to insert values in the above table created i.e. course table following query is used :-

INSERT INTO course VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM course;

To create a table for instructor i.e. instructor(pk(iid), salary, inst_name) following query is used :-

CREATE TABLE instructor(

iid varchar(50) NOT NULL PRIMARY KEY,

salary int(80),

inst_name varchar(40)

);

Now to insert values in the above table created i.e. instructor table following query is used :-

INSERT INTO instructor VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM instructor;

To create a table for department i.e. department(pk(dept_name), budget) following query is used :-

CREATE TABLE course(

dept_name varchar(50) NOT NULL PRIMARY KEY,

budget varchar(50)

);

Now to insert values in the above table created i.e. department table following query is used :-

INSERT INTO department VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM department;

To create a table for student i.e. student(pk(sid), student_name, tot_cred) following query is used :-

CREATE TABLE student(

sid int(50) NOT NULL PRIMARY KEY,

student_name varchar(40),

tot_cred varchar(40)

);

Now to insert values in the above table created i.e. student table following query is used :-

INSERT INTO student VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM student;

To create a table for time_slot i.e. time_slot(pk(time_slot_id), day, start_time, end_time) following query is used :-

CREATE TABLE time_slot(

time_slot_id varchar(50) NOT NULL PRIMARY KEY,

day varchar(40),

start_time varchar(40),

end_time varchar(40)

);

Now to insert values in the above table created i.e. time_slot table following query is used :-

INSERT INTO time_slot VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM time_slot;

To create a table for section i.e. section(pk(section_id), pk(semester), pk(year)) following query is used :-

CREATE TABLE section(

section_id varchar(50) NOT NULL PRIMARY KEY,

semester varchar(40) NOT NULL PRIMARY KEY,

year varchar(40)NOT NULL PRIMARY KEY

FOREIGN KEY (dept_name) REFERENCES department(dept_name),

FOREIGN KEY (building_name) REFERENCES building(building_name),

);

Now to insert values in the above table created i.e. section table following query is used :-

INSERT INTO section VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM section;

To create a table for course_dept i.e. course_dept(pk(dept_name, course_id)) following query is used :-

CREATE TABLE course_dept(

dept_name varchar(50) NOT NULL PRIMARY KEY,

course_id varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (dept_name) REFERENCES department(dept_name),

FOREIGN KEY (course_id) REFERENCES course(course_id)

);

Now to insert values in the above table created i.e. course_dept table following query is used :-

INSERT INTO course_dept VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM course_dept;

To create a table for inst_dept i.e. inst_dept(pk(dept_name, iid)) following query is used :-

CREATE TABLE course_dept(

dept_name varchar(50) NOT NULL PRIMARY KEY,

iid varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (dept_name) REFERENCES department(dept_name),

FOREIGN KEY (iid) REFERENCES instructor(iid)

);

Now to insert values in the above table created i.e. inst_dept table following query is used :-

INSERT INTO inst_dept VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM isnt_dept;

To create a table for mentors i.e. mentors(pk(iid,sid)) following query is used :-

CREATE TABLE course_dept(

sid varchar(50) NOT NULL PRIMARY KEY,

iid varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (sid) REFERENCES student(sid),

FOREIGN KEY (iid) REFERENCES instructor(iid)

);

Now to insert values in the above table created i.e. mentors table following query is used :-

INSERT INTO mentors VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM mentors;

To create a table for stud_dept i.e. stud_dept(pk(dept_name, sid)) following query is used :-

CREATE TABLE stud_dept(

dept_name varchar(50) NOT NULL PRIMARY KEY,

sid varchar(50) NOT NULL PRIMARY KEY,

section_id varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (dept_name) REFERENCES department(dept_name),

FOREIGN KEY (sid) REFERENCES student(sid),

FOREIGN KEY (section_id) REFERENCES section(section_id)

);

Now to insert values in the above table created i.e. stud_dept table following query is used :-

INSERT INTO stud_dept VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM stud_dept;

To create a table for sec_time_slot i.e. sec_time_slot(pk(time_slot_id), pk(section_id, semester, year)) following query is used :-

CREATE TABLE sec_time_slot(

time_slot_id varchar(50) NOT NULL PRIMARY KEY,

section_id varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (time_slot_id) REFERENCES time_slot(time_slot_id),

FOREIGN KEY (section_id, semester, year) REFERENCES section(section_id, semester, year)

);

Now to insert values in the above table created i.e. inst_dept table following query is used :-

INSERT INTO sec_time_slot VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM sec_time_slot;

To create a table for sec_class i.e. sec_class(pk(section_id, room_number)) following query is used :-

CREATE TABLE sec_class(

section_id varchar(50) NOT NULL PRIMARY KEY,

room_number varchar(50) NOT NULL PRIMARY KEY,

FOREIGN KEY (section_id) REFERENCES section(section_id),

FOREIGN KEY (room_number) REFERENCES classroom(room_number)

);

Now to insert values in the above table created i.e. sec_class table following query is used :-

INSERT INTO sec_class VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM sec_class;

To create a table for inst_dept i.e. teaches(pk(iid), pk(section_id, semester, year)) following query is used :-

CREATE TABLE teaches(

section_id varchar(50) NOT NULL PRIMARY KEY,

iid varchar(50) NOT NULL PRIMARY KEY,

   FOREIGN KEY (section_id, semester, year) REFERENCES section(section_id, semester, year),

FOREIGN KEY (iid) REFERENCES instructor(iid)

);

Now to insert values in the above table created i.e. inst_dept table following query is used :-

INSERT INTO teaches VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM teaches;

To create a table for prereq i.e. prereq(pk(course_id) following query is used :-

CREATE TABLE prereq(

course_id varchar(40) NOT NULL PRIMARY KEY,

FOREIGN KEY (course_id) REFERENCES course(course_id)

);

Now to insert values in the above table created i.e. inst_dept table following query is used :-

INSERT INTO prereq VALUES(value1, value2, value3, ...........); -> whatever values are to inserted will be inserted here

Now to see/show the table we use the floowing query :-

SELECT * FROM prereq;


Related Solutions

In MySQL, create a new schema titled <yourlastname>module3. Using the below file, create the tables in...
In MySQL, create a new schema titled <yourlastname>module3. Using the below file, create the tables in your new schema and populate with the supplied data. Tables do not have keys. Do not define them at this time. There are errors in the data population (INSERT) statements. It is your job to find the errors and correct them. This is important. You will need correct data for future exercises in this module. In the submission area, choose Write Submission and identify...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various...
• Relational Schema Create a relational database schema consisting of the four relation schemas representing various entities recorded by a furniture company.   Write CREATE TABLE statements for the following four relation schemas. Define all necessary attributes, domains, and primary and foreign keys. Customer(CustomerID, Name, Address) FullOrder(OrderID, OrderDate, CustomerID) Request(OrderID, ProductID, Quantity) Product(ProductID, Description, Finish, Price) You should assume the following: Each CustomerID is a number with at most three digits, each OrderID is a number with at most five digits,...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection...
Database: Question 11 Using the ERD from problem 10, create the relational schema.(Create an appropriate collection of attributes for each of the entities. Make sure you use the appropriate naming conventions to name the attributes.)
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...
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...
using mysql and the schema is provided below. thanks In this lab, you will be manipulating...
using mysql and the schema is provided below. thanks In this lab, you will be manipulating the database to add, delete and modify the values in the database. Please use a "select * from..." after each query to show the effects of your data manipulation query. 1. The title 'Time Flies' now has a new track, the 11th track 'Spring', which is 150 seconds long and has only a MP3 file. Insert the new track into Tracks table (Don’t hand-code...
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...
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...
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists...
using the lyrics database schema in mysql provided below. 1.)List the artist name of the artists who do not have a webaddress and their leadsource is “Directmail”? 2.)List the names of members in the artist called 'Today'. 3.)Report the total runtime in minutes FOR EACH album in the Titles table. 4.)List the firstname, lastname of members who are represented by the salesperson “Lisa Williams” 5.)List EACH salesperson’s firstname along with the number of Members that EACH SalesPerson represents. below is...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT