Question

In: Computer Science

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 the last 4 digits of your Student-

ID by using Alter command. Explain why you choose them as the primary keys; (10%)

c) Specify one Update, one Delete, one Select, one Join, and one View in SQL that are needed by

your database application

Solutions

Expert Solution

Replace 4SID with your StudentId
a) Creating two tables

CREATE TABLE `course4SID` (
`CourseId` INT NOT NULL,
`CourseName` VARCHAR(45) NULL,
`TotalMarks` INT NULL,
`Teacher` VARCHAR(45) NULL,
PRIMARY KEY (`CourseId`));

CREATE TABLE `sql_0112191`.`student4sid` (
`StudentID` INT NOT NULL,
`StudentName` VARCHAR(45) NULL,
`Course1` INT NULL,
`Course2` INT NULL,
PRIMARY KEY (`StudentID`),
INDEX `CourseId_idx` (`Course1` ASC) VISIBLE,
CONSTRAINT `CourseId`
FOREIGN KEY (`Course1`)
REFERENCES `sql_0112191`.`course4sid` (`CouseId`)
ON DELETE NO ACTION
ON UPDATE NO ACTION);

Inserting data

INSERT INTO `course4sid` (`CourseId`, `CourseName`, `TotalMarks`, `Teacher`) VALUES ('1', 'Maths', '150', 'Teacher1');
INSERT INTO `course4sid` (`CourseId`, `CourseName`, `TotalMarks`, `Teacher`) VALUES ('2', 'Physics', '100', 'Teacher2');
INSERT INTO `course4sid` (`CourseId`, `CourseName`, `TotalMarks`, `Teacher`) VALUES ('3', 'Chemistry', '80', 'Teacher3');
INSERT INTO `course4sid` (`CourseId`, `CourseName`, `TotalMarks`, `Teacher`) VALUES ('4', 'Computers', '100', 'Teacher4');

INSERT INTO `student4sid` (`StudentID`, `StudentName`, `Course1`, `Course2`) VALUES ('101', 'John', '1', '2');
INSERT INTO `student4sid` (`StudentID`, `StudentName`, `Course1`, `Course2`) VALUES ('102', 'Max', '1', '3');
INSERT INTO `student4sid` (`StudentID`, `StudentName`, `Course1`, `Course2`) VALUES ('103', 'Kevin', '2', '3');
INSERT INTO `student4sid` (`StudentID`, `StudentName`, `Course1`, `Course2`) VALUES ('104', 'Peter', '2', '4');

1 Maths 150 Teacher1
2 Physics 100 Teacher2
3 Chemistry 80 Teacher3
4 Computers 100 Teacher4
101 John 1 2
102 Max 1 3
103 Kevin 2 3
104 Peter 2 4

b) Adding 4 Digits of student id to the column

ALTER TABLE `course4sid` CHANGE COLUMN `CourseId` `CourseId4SID` INT NOT NULL ;

ALTER TABLE `student4sid` CHANGE COLUMN `StudentID` `StudentID4SID` INT NOT NULL ;

We chose the CourseId4SID and StudentID4SID as the Primary Key because they can uniquely identify each row of the table

CourseId4SID int(11) NO PRI
CourseName varchar(45) YES
TotalMarks int(11) YES
Teacher varchar(45) YES
StudentID4SID int(11) NO PRI
StudentName varchar(45) YES
Course1 int(11) YES MUL
Course2 int(11) YES

c) SQL Statements
UPDATE `student4sid` SET `Course2` = '4' WHERE (`StudentID4SID` = '102');

101 John 1 2
102 Max 1 4
103 Kevin 2 3
104 Peter 2 4

DELETE FROM `student4sid` WHERE (`StudentID4SID` = '104');

101 John 1 2
102 Max 1 4
103 Kevin 2 3

SELECT * FROM student4sid;

101 John 1 2
102 Max 1 4
103 Kevin 2 3

SELECT StudentID4SID,StudentName,CourseName FROM student4sid INNER JOIN course4sid WHERE Course1=CourseId4SID;

Dispaying the student with their Course1 Names

101 John Maths
102 Max Maths
103 Kevin Physics

CREATE OR REPLACE VIEW `new_view` AS SELECT StudentID4SID,StudentName,CourseName FROM student4sid INNER JOIN course4sid WHERE Course1=CourseId4SID;;

101 John Maths
102 Max Maths
103 Kevin Physics

Related Solutions

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...
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 world_x database you installed on your MySQL Workbench, create a new table named “independence”...
Using the world_x database you installed on your MySQL Workbench, create a new table named “independence” with the following attributes (columns): A field named “id” which has data type auto_increment, A field named “country_name” which has data type varchar(50), and A field named “independence_date” which has type “date.” After you create the table, run the following SQL command: INSERT INTO independence(country_name, independence_date) VALUE (‘United States’,’1776-07-04’) Submit a 1-page Microsoft Word document that shows the following: The SQL command you used...
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...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that...
This is in MySQL Part one: Using the MySQL Workbench Data Modeler, construct a diagram that shows the table in 3rd Normal Form. Part two: Provide a summary of the steps you took to achieve 3rd Normal form. Include your rationale for new table creation, key selection and grouping of attributes. Table Details: The Anita Wooten Art Gallery wishes to maintain data on their customers, artists and paintings. They may have several paintings by each artist in the gallery at...
You are asked to design a relational database for a simple course registration software application for...
You are asked to design a relational database for a simple course registration software application for your school. The relational database must have the following information about the student, the course, and the registration, respectively StudentID, FirstName, LastName, DataOfJoining, and Major CourseNumber, CourseName,InstructorName, StartDate, EndDate, NumberOfCredits ReferenceID, StudentID,CourseID, DateOfRegistration Apply the following constrains while designing the database Each student in the database must be uniquely identifiable Each course listed in the database must be have unique CourseNumber Each course registration...
Using MySQL 8.xx create a database with the following characteristics. . A. Your design MUST meet...
Using MySQL 8.xx create a database with the following characteristics. . A. Your design MUST meet the requirements for Third Normal Form B. Create a database (you will need multiple tables) to store employee information. This information will include: Employee Number, First Name, Last Name, Date of birth, Address, city, state, zip, department, job title, supervisor, health insurance number, health insurance provider, dental insurance number, dental insurance provider, spouse/partner, children, children's ages. C. Populate the table with multiple records which...
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...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me!...
Using MySQL Workbench to write and run the following steps, and take a screenshot for me! Create a species table and a specimen table. In the species table, include attributes that reflect the name of the species, a general description of the species, and any other attributes you feel relevant. In the specimens table, include an ID for the specimen, a reference to the species which it is, the date which it was observed, and any relevant details like height,...
how can object -relational database be used to implement an SDBMS?
how can object -relational database be used to implement an SDBMS?
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT