Basic SQL
✕Table Creation
Question 1 of 5
- Create database named
sample_db. - Inside
sample_db, create all tables from lecture slide with proper data types. - Add records in each table as shown in lecture slide.
- Refresh database in DBeaver and validate table structure.
- Run
SELECT *query on each table to validate inserted records.
Connect your PostgreSQL database in DBeaver and:- Create database named
Table with Constraints
Question 2 of 5
- Drop tables created in previous exercise
- Customer
-
id=> Serial, PRIMARY KEY -registered_date=> DEFAULT valuenow-name=> NOT NULL -phone=> UNIQUE, CHECK:LENGTH = 10-address=> DEFAULT valueNEPAL - Employee
-
id=> Serial, PRIMARY KEY -name=> NOT NULL -joined_date=> DEFAULT valuenow-department=> CHECK:department IN ('HR', 'SALES', 'TECH')-salary=> CHECK:salary > 0-manager_id=> FOREIGN KEY referencingemployee(id) - Product
-
id=> Serial, PRIMARY KEY -name=> NOT NULL -price=> CHECK:price > 0 - Transaction
-
id=> Serial, PRIMARY KEY -customer_id=> FOREIGN KEY referencingcustomer(id)-cashier_id=> FOREIGN KEY referencingemployee(id)-product_id=> FOREIGN KEY referencingproduct(id)-product_qty=> CHECK:quantity > 0-txn_date=> DEFAULT valuenow
Alter Table
Question 3 of 5
- Remove column
discount_pricefrom transaction. - Add column
total_pricein transaction with proper data type & constraint. - Rename column
cashier_idtoemployee_idin transaction - Add
mobile_numberin employee making it unique. - Rename table
customertocustomer_info. - Add column
brandin product with default valueGeneric. - Remove
is_vipfrom customer_info, addcustomer_typewith default valueRegular.
- Remove column
Restoring Data
Question 4 of 5
- Download DDL Script and DML scripts.
- Open both scripts in text editor and understand the commands.
- Run commands from
DDL.sqlto create tables,DML.sqlto add data in your database. - Validate table structure and data with DBeaver GUI.
- Make ER diagram of the database with DBeaver.
Querying Data
Question 5 of 5
- Get
first_name,last_name,phone,addressof all customer & export as csv. - List all the products with
price above 500. - List all the transaction that happen in month of
June, 2025. - List
Name,Address,Emailof customer from Kathmandu / Pokhara. If there is no email, you have to display-. Sort result by name & address. - List HR employees who have already resigned from the mart.
- Find top 5 expensive product. Exclude brands
ElectroVision,BeanBrew. - List customer who uses Gmail.
- Show all unique location from customer table.
- Find the customer from
Rasuwawho don't have email address. - Find the employee who don't have supervisor.
- Find
Name,EmailandPhone numberof customer from Dhangadi. - Find
Name,Departmentof top 10 highest paid employee. - Get top 10 product that are low in stock excluding brand
ComfortSit. - Find customer whose number doesn't start with
98. - Practice Questions from Hacker Rank.
- Get
