Question: 1 a . Create a unique index for inventory table on partno and name it as part _ inv _ index. Query: create UNIQUE INDEX

1a. Create a unique index for inventory table on partno and name it as part_inv_index.
Query: create UNIQUE INDEX part_inv_index ON inventory (partno);
Output: INDEX PART_INV_INDEX created.
1b. Create an index cust_balance_indx to support sorting customers by postal_code, balance desc.
Query: CREATE INDEX cust_balance_indx ON customer (postal_code ASC, balance DESC);
Output: Index CUST_BALANCE_INDX created.
2a. Permit joshi to update customer table.
Query: GRANT UPDATE ON customer TO joshi;
Output: Grant succeeded.
2b. Permit everyone to select all on your inventory table.
Query: GRANT SELECT ON inventory TO PUBLIC;
Output: Grant succeeded.
3a. Add a character type column named customer_type with 5 character positions to customer table.
Query: ALTER TABLE customer ADD customer_type CHAR(5);
Output: Table CUSTOMER altered.
3b. Now change the width of customer_type to 10 characters in customer table.
Query: ALTER TABLE customer MODIFY customer_type CHAR(10);
Output: Table CUSTOMER altered.
3c. Rename Price in Item table to ListPrice.
Query: ALTER TABLE Item RENAME COLUMN Price TO ListPrice;
Output: Table ITEM altered.
4a. Modify Enroll table (refer to Tiny College) to add a new column gradepoints. (For the Follwing questions, refer to the ERD of Tiny College placed in Module 1). Tiny College ERD.pdf
Before doing the query I created the tables for Tiny College ERD: Create table Professor(Prof_Num int Primary key,Dept_Code VARCHAR(30),Prof_Speciality VARCHAR(30),Prof_Rank int,Prof_Lname VARCHAR(30),Prof_Fname VARCHAR(30),Prof_Intial VARCHAR(10),Prof_Email VARCHAR(30));
Create table School(School_Code int Primary key,School_Name VARCHAR(30),Prof_Num int);
Create table Department(Dept_Code int Primary key,Dept_Name VARCHAR(30),School_Code int,Prof_Num int);
Create table Course(Crs_Code int Primary key,Dept_Code int,Crs_Title VARCHAR(30),CRS_Description VARCHAR(30),CRS_Credit int);
Create table Class_(Class_Code int Primary key,Class_Section int,Class_Time VARCHAR(30),Crs_Code int,Prof_Num int,Room_Code int);
Create table Student(Stu_Num int Primary key,Dept_Code int,Stu_Lname VARCHAR(30),Stu_Fname VARCHAR(30),Stu_Intial VARCHAR(30),Stu_Email VARCHAR(30),Prof_Num int);
Create table Enroll(Class_Code int,Stu_Num int,Enroll_Date date,Enroll_Grade VARCHAR(30));
Create table Room(Room_Code int Primary key,Room_Type VARCHAR(30),Bldg_Code int);
Create table Building(Bldg_Code int Primary key,Bldg_Name VARCHAR(30),Bldg_Location VARCHAR(30));
Query: ALTER TABLE Enroll ADD gradepoints DECIMAL(4,2);
Output: Table ENROLL altered.
4b. Now use case statement to fill gradepoint value of 4 if the grade is A,3 for B,2 for C,1 for D, and .05 for F.
Query: UPDATE Enroll
SET gradepoints = CASE
WHEN enroll_grade ='A' THEN 4
WHEN enroll_grade ='B' THEN 3
WHEN enroll_grade ='C' THEN 2
WHEN enroll_grade ='D' THEN 1
WHEN enroll_grade ='F' THEN 0.05
ELSE NULL -- Handle other cases as needed
END;
Output: 5 rows updated.
5. Now compute Average GPA in each class. Display class_code, Class_GPA. Assume all courses are 3 credit courses. A general formula for GPA would be sum(gradepoints x Hrs)/sum(Hrs). Here you can just take an average of gradepoints as the credit hours are same for all courses.
Query: SELECT class_code, AVG(gradepoints) AS Class_GPA
FROM Enroll
GROUP BY class_code;
Output: (null)2.01
6. Create a view Course_Grades showing GPA of all the students in a class with Class_Code: 11794. Include Student_Number, Student_Name, GPA. Grant read ability to Joshi for this view.
Provide a select statement, via which, Joshi can see the names, and GPAs of students with GPA above 3.0, where GPAs are arranged in a descending order.
Query Part 1: CREATE VIEW Course_Grades AS
SELECT
e.stu_num AS Student_Number,
s.stu_fname AS First_Name,
s.stu_lname AS Last_Name,
e.class_code AS Class_Code,
e.gradepoints AS GPA
FROM Enroll e
JOIN Student s ON e.stu_num = s.stu_num
WHERE e.class_code ='11794';
GRANT SELECT ON Course_Grades TO joshi;
Output Part 1: View COURSE_GRADES created.
Grant succeeded.
Query Part 2: SELECT first_name, last_name, GPA
FROM Course_Grades
WHERE GPA >3.0
ORDER BY GPA DESC;
Output Part 2: no data
Is this correct?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!