Question

In: Computer Science

Create tables according to the mapping. Add 2 records to each. Create 5 queries for database...

Create tables according to the mapping. Add 2 records to each. Create 5 queries for database of 3 table joins to use most of the tables or group of tables in database. You should not have tables that are of no use.

Student(ssn, name, major)

Class(classID, name, f_ssn)

Faculty(ssn, name, office_num, dept_id)

Department(Dept_id, office_num, f_ssn)

Enroll(s_ssn, classID, grade)

Professor(f_ssn, alma-mater, tenured)

Instructor(f_ssn, term_degree, type)

Lecture(classID, method)

Lab(classID, location)

Person(ssn, dob, gender)

Solutions

Expert Solution

Solution:

Here I am using SQL Editor for creating Tables and queries

Step1:Table Creation and value insertion

Queries:

Create table Person(ssn int primary key,dob datetime,gender char(1));
Insert into Person values(1,'05/20/1990','M')
Insert into Person values(2,'08/20/1994','F')
Insert into Person values(3,'07/20/1990','M')
Insert into Person values(4,'08/28/2004','F')
Insert into Person values(5,'05/20/2005','M')
Insert into Person values(6,'08/25/1994','F')
Insert into Person values(7,'05/20/1993','M')
Insert into Person values(8,'08/20/1992','F')
Insert into Person values(9,'07/20/1991','M')
select * from Person;
Create table Professor(f_ssn int Primary key,alma_mater varchar(50), tenured varchar(15),foreign key(f_ssn) references Person(ssn))
Insert into Professor values(1,'Oxford University','Permanet')
Insert into Professor values(2,'IIT Chennai','Temporay')
Insert into Professor values(3,'IIM Mumbai','Permanent')
Insert into Professor values(7,'IIT Kanpur','Permanet')
Insert into Professor values(8,'Oxford University','Temporay')
Insert into Professor values(9,'IIM Mumbai','Permanent')
select * from Professor;
Create table Instructor(f_ssn int Primary key, term_degree int, type varchar(50),foreign key(f_ssn) references Professor(f_ssn))
Insert into Instructor values(1,4,'Computer Science Engineering')
Insert into Instructor values(2,4,'Electronics Engineering')
Insert into Instructor values(3,2,'Management')
Insert into Instructor values(7,4,'Computer Science Engineering')
Insert into Instructor values(8,4,'Electronics Engineering')
Insert into Instructor values(9,2,'Management')
select * from Instructor;
Create table Department(Dept_id varchar(25) , office_num int ,f_ssn int,Primary key(Dept_id), foreign key(f_ssn) references Professor(f_ssn))
Insert into Department values('Computer Science',105,1)
Insert into Department values('Electronics Engineering',108,2)
Insert into Department values('Management',110,3)
select * from Department;
Create table Faculty(ssn int primary key,name varchar(30), office_num int , dept_id varchar(25),foreign key(dept_id) references Department(dept_id),
foreign key(ssn) references Person(ssn))
Insert into Faculty values(1,'John',105,'Computer Science')
Insert into Faculty values(2,'Tom',108,'Electronics Engineering')
Insert into Faculty values(3,'Anna',110,'Management')
Insert into Faculty values(7,'Syam',106,'Computer Science')
Insert into Faculty values(8,'Neema',109,'Electronics Engineering')
Insert into Faculty values(9,'Sani',1110,'Management')
select * from Faculty;
Create table Student(ssn int primary key,name varchar(30),majour varchar(25),foreign key(ssn) references Person(ssn),foreign key(majour) references Department(dept_id))
Insert into Student values(4,'Mary','Computer Science')
Insert into Student values(5,'Easther','Electronics Engineering')
Insert into Student values(6,'Daniel','Management')
select * from Student;
Create table Class(classID int Primary key, name varchar(25), f_ssn int,foreign key(f_ssn) references Professor(f_ssn),foreign key(name) references Department(dept_id))
Insert into Class values(1,'Computer Science',7)
Insert into Class values(2,'Electronics Engineering',8)
Insert into Class values(3,'Management',9)
select * from Class;
Create table Enroll(s_ssn int primary key , classID int , grade char(2),foreign key(s_ssn) references Person(ssn),foreign key(classID) references Class(classID))
Insert into Enroll values(4,1,'A+')
Insert into Enroll values(5,2,'A')
Insert into Enroll values(6,3,'A')
select * from Enroll;
Create table Lecture(classID int primary key, method varchar(50),foreign key(classID) references Class(classID))
Insert into Lecture values(1,'Personalized Learning ')
Insert into Lecture values(2,'Personalized Learning ')
Insert into Lecture values(3,'Flipped Classrooms ')
select * from Lecture;
Create table Lab(classID int primary key , location varchar(50),foreign key(classID) references Class(classID))
insert into Lab values(1,'Building 1')
insert into Lab values(2,'Building 2')
insert into Lab values(3,'Building 3')
select * from Lab;

QUERIES in SQL EDITOR

RESULTING Tables

5 Queries using atleast 3 joins

1.Select all student's name,Date Of Birth ,Grade and Gender

Query:

select s.name as Student,P.dob,E.grade,P.gender from Student S join Person P on S.ssn=P.ssn join Enroll E on E.s_ssn=P.ssn

Query in Sql Editor:

RESULT

2.Select All Faculty name ,Dob,Gender, Office number , Department,term_degree and Type

Query:

select F.name,P.dob,P.gender,F.office_num,F.dept_id,I.term_degree,I.type from Faculty F join Instructor I on F.ssn=I.f_ssn join Person P on F.ssn=P.ssn

Query in Sql Editor:

RESULT

3.Select All Department, Office Number Of Department,No Of classes

Query:

select d.Dept_id,d.office_num ,Count(d.f_ssn) as NoOfFaculties,count(c.classID) AS NOofclasses from Department d join Faculty F on d.Dept_id=F.Dept_id Join Class C on d.Dept_id=c.name
group by d.Dept_id,d.office_num

Query in Sql Editor:

RESULT:

4.Select all class,Location,method of teaching

Query:

select distinct c.name As Class, L.method as MethodOfTeaching,location as Location from Class c join Lecture L on c.classID=L.classID
join Lab Lb on c.classID=Lb.classID join Faculty F on c.name=F.dept_id join Person P on c.f_ssn=P.ssn

Query in Sql Editor:

RESULT:

5.Select student name, class,Department ,Faculty

Query:

select s.name as Student,E.classID as Class,s.majour as Department , F.name AS ClassFaculty from Student s join Person p on s.ssn=p.ssn
join Enroll E on s.ssn=E.s_ssn join Class c on E.classID=c.classID join Faculty F on c.f_ssn=F.ssn

Query in Sql Editor:

RESULT

If you have any further queries.please comment....


Related Solutions

Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient,...
Database exercise: inpatient cases Create database using name RUMKIT Create tables below in that database patient(idPatient, fullName, biologicalMother, birthdate, address) doctor(idDr, fullName, specialization, consulRates) inpatient(idPatient, entryTime, outTime, idDr, idRoom). Please make entryTime as column that is going to be filled automatically when care record is being add room(idRoom, roomName, cost) fill the data above to each table Create sql query and relational algebra expressions for the query Please give me detailed answer so I could learn from it. Thank you...
Database Design Design a database and show the relationship between each tables. I need multiple tables....
Database Design Design a database and show the relationship between each tables. I need multiple tables. *Must meet the requirements for Third Normal Form. These are the information for employee DB. 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.
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.
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.
Part 2: You will create five tables in your ColonialAdventureTours database. Please do not write your...
Part 2: You will create five tables in your ColonialAdventureTours database. Please do not write your own SQL Commands for this task, use data found in the following Colonial_create.txt file and copy and paste the commands into MySQL workbench. Then add Primary key, Foreign key, and not null constraints appropriately. Then run your codes. Note: Remember that since you enforced referential integrity (foreign key constraints) that you must create the "primary" tables before you can create the "related" tables in...
Create the following SQL queries using the lyrics database below 1. List the first name, last...
Create the following SQL queries using the lyrics database below 1. List the first name, last name, and region of members who do not have an email. 2. List the first name, last name, and region of members who do not have an email and they either have a homephone ending with a 2 or a 3. 3. List the number of track titles that begin with the letter 's' and the average length of these tracks in seconds 4....
Experiment with SQL queries on 2 tables: Background: Normalized databases will involve data that is organized...
Experiment with SQL queries on 2 tables: Background: Normalized databases will involve data that is organized into 2 or more tables. However, to answer queries, the data from 2 (or more) tables will need to be joined together to get the relevant information. Join operations in SQL are accomplished in the following manner: Indicate the tables involved in the query in the FROM clause Specify relationship/condition between columns in from the tables. Exercise: For this part of the exercise the...
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)...
Create a database with two tables as follows:- Students - StudentID, Name, Program FeePayment - StudentID,...
Create a database with two tables as follows:- Students - StudentID, Name, Program FeePayment - StudentID, Date, Description, Amount 1. Create a stored procedure that receives all the details of a student including fees and proceeds to insert insert the student details into the student details and the fee payment into the FeePayment table. All the operations should be done within a single transaction in a stored procedure. Note that the stored procedure works like a function that receives parameters....
Please create the following tables for a tool rental database with appropriate primary keys & foreign...
Please create the following tables for a tool rental database with appropriate primary keys & foreign keys. Assumptions: 1. Each tool belongs to a category. 2. Each category may have a parent category but the parent category should not have a parent category (so at most two levels). E.g., a Tool A belongs to the electric mower, and electric mowers belong to mowers. Mower has no parent category. 3. Each tool can be rented at different time units. The typical...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT