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...
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...
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...
how can object -relational database be used to implement an SDBMS?
how can object -relational database be used to implement an SDBMS?
Using WORKBENCH: 1. Create the database below via an ER Diagram in Workbench (take screen shots...
Using WORKBENCH: 1. Create the database below via an ER Diagram in Workbench (take screen shots of the diagram) 2. Go to the database table view and take a screen shot of the table(s) 3. Go to the data entry tool and enter at least three lines of data (in each table). Take screen shots. Create a database that is in third normal form for the following: You are a nerd and have decided to organize your comic books in...
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...
Design the database using the ER approach. Then using Java and SQL, implement the following functionality:...
Design the database using the ER approach. Then using Java and SQL, implement the following functionality: Implement a button called “Initialize Database”. When a user clicks it, all necessary tables will be created (or recreated) automatically, with each table be populated with at least 10 tuples so that each query below will return some results. All students should use the database name “sampledb”, username “john”, and password “pass1234”. Implement a user registration and login interface so that only a registered...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT