SQL Lab 1 - 5 Codes (DBT)
SQL Lab 1 - 5 Codes (DBT)
DEPT_NAME VARCHAR(50),
LOC VARCHAR2(14),
BUDGET NUMBER(7,2)
);
COURSE_ID VARCHAR(10),
TITLE VARCHAR(50),
DEPT_NAME VARCHAR(50),
CREDITS VARCHAR(50)
);
INSTRUCTORS_ID VARCHAR2(50),
DEPT_NAME VARCHAR(50),
SALARY NUMBER(8,2)
);
STUDENT_ID VARCHAR2(50),
STUDENT_NAME VARCHAR2(50) NOT NULL,
DEPT_NAME VARCHAR(50),
TOTAL_CREDITS VARCHAR(50)
);
BUILDING_NAME VARCHAR(50),
ROOM_NO NUMBER(7),
ROOM_CAPACITY NUMBER(7,2)
);
COURSE_ID VARCHAR(50),
SEC_ID VARCHAR(50),
YEAR NUMBER(7),
SEMISTER NUMBER(8,2)
);
2. Insert proper values into the tables and display the records.
LAB 2
1. Implement the following Data Definition Language(DDL) SQL Commands
with
c. Truncate Table
d. Create View
e. Drop Table
CODES USED:
AGE INT,
CHECK (AGE>=18),
);
EMPLOYEEID INT,
AGE INT
);
FROM HR.DEPARTMENTS
Lab 3
Write the SQL statements to accomplish the following tasks:
(1) Create the following 3 tables for your online store. The primary keys are
underlined, and the foreign keys are shown in italic. You can personalize the
tables if needed to be fit to store the information you need for the products
you sell on your website.
(3) List all records from the PRODUCT, SALE and SALEITEM table.
(4) Update the price of one of your products in the PRODUCT table to cost
Rs.100 morethan original price.
(5) Delete all products with price higher than 10,000 from your PRODUCT
table.
Hint: You can insert such a product first and then use this command to delete
it for testing purposes
Codes used
CREATE TABLE PRODUCT (
PRICE INT,
);
);
SALEID INT,
PRODUCTID INT,
QUANTITY INT
);
UPDATE PRODUCT
LAB 4
(1) With the example relations of your choice, demonstrate
the following:
(a) Aggregate Functions:
Average: avg
Minimum: Min
Maximum: Max
Total: sum
Count: count
(b) Set Operations:
union
intersect
except
(c) Nested Subqueries
Codes used
CREATE TABLE PRODUCT (
PRICE INT,
);
);
FROM PRODUCT;
FROM PRODUCT;
FROM PRODUCT;
SELECT SUM(PRICE)
FROM PRODUCT;
SELECT COUNT(PRICE)
FROM PRODUCT;
UNION
INTERSECT
ORDER BY PRODUCTID;
MINUS
ORDER BY PRODUCTID;
SELECT AVG(PRICE)
FROM PRODUCT;
SELECT *
FROM PRODUCT
SELECT *
FROM PRODUCT
SELECT AVG(PRICE)
FROM PRODUCT);
SELECT *
FROM SALE
WHERE PRODUCTID = (
SELECT PRODUCTID
FROM PRODUCT
WHERE PRICE = (
SELECT MAX(PRICE)
FROM PRODUCT));
LAB 5
(1) With an example scenario of your choice, demonstrate
the following Join expressions:
a. left outer join
b. right outer join
c. full outer join
d. inner join
Optional Question:
(2) Demonstrate the implementation of Assertions and
Triggers in SQL with an example queries.
Codes used
CREATE TABLE PRODUCT (
PRICE INT,
);
);
SELECT *
FROM PRODUCT RIGHT JOIN SALE
SELECT *
DECLARE
PRICE_DIFF NUMBER;
BEGIN
END;