0% found this document useful (0 votes)
17 views64 pages

Final Database

The document outlines a series of SQL labs focused on database creation, manipulation, and querying. It includes tasks related to SQL constraints, views, triggers, indexing, NoSQL examples, and object-oriented database support. Each lab contains specific objectives, SQL code examples, and questions to reinforce learning on various database concepts and operations.

Uploaded by

MiHawk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views64 pages

Final Database

The document outlines a series of SQL labs focused on database creation, manipulation, and querying. It includes tasks related to SQL constraints, views, triggers, indexing, NoSQL examples, and object-oriented database support. Each lab contains specific objectives, SQL code examples, and questions to reinforce learning on various database concepts and operations.

Uploaded by

MiHawk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 64

Table of Contents:

LAB Title

1 Use the given SQL code to populate the database schema and complete
the query given below. (SQL Constraints, Views)

2 Consider the following two tables and answer the following questions.
(Aggregation and Joins)

3 Use the given HR Schema and answer the following questions.

4 Practice DDLs and Queries

5 Practice with Object Types and Collections in Oracle LiveSQL

6 Practice the given queries (Triggers)

7 Indexing and Query Cost Analysis

8 NoSQL Database Simple Examples

9 Object-Oriented Database Support in Oracle Database

10 Distributed Database Setup using Postgres DB


Lab 1: Use the given SQL code to populate the database schema and
complete the query given below. (SQL Constraints, Views)

Creation:

CREATE DATABASE AdvanceDataBaseLab1;

use AdvanceDataBaseLab1;

CREATE TABLE DEPARTMENT(


DEPARTMENT_ID integer,
DEPARTMENT_NAME varchar(30),
MANAGER_ID integer,
PRIMARY KEY(DEPARTMENT_ID)
);

--Note : Varchar2 is specific to Oracle. I'm using sql server so, varchar

CREATE TABLE JOB(


JOB_ID integer,
JOB_TITLE varchar(60),
MIN_SALARY decimal(9,2),
MAX_SALARY decimal(9,2),
PRIMARY KEY(JOB_ID));

CREATE TABLE EMPLOYEE(


EMPLOYEE_ID integer,
FIRST_NAME varchar(30),
MIDDLE_NAME varchar(30),
LAST_NAME varchar(30),
EMAIL varchar(320),
PHONE_NUMBER varchar(15),
HIRE_DATE date,
JOB_ID integer,
SALARY varchar,
COMMISSION decimal(5,2),
MANAGER_ID integer,
DEPARTMENT_ID integer,
PRIMARY KEY (EMPLOYEE_ID),
FOREIGN KEY (JOB_ID) REFERENCES JOB(JOB_ID),
FOREIGN KEY (DEPARTMENT_ID) REFERENCES
DEPARTMENT(DEPARTMENT_ID)
);
CREATE TABLE JOB_HISTORY(
EMPLOYEE_ID integer,
START_DATE date,
END_DATE date,
JOB_ID integer,
DEPARTMENT_ID integer,
PRIMARY KEY (EMPLOYEE_ID, START_DATE),
FOREIGN KEY (EMPLOYEE_ID) REFERENCES EMPLOYEE(EMPLOYEE_ID),
FOREIGN KEY (JOB_ID) REFERENCES JOB(JOB_ID),
FOREIGN KEY (DEPARTMENT_ID) REFERENCES
DEPARTMENT(DEPARTMENT_ID)
);

INSERT INTO DEPARTMENT VALUES (10, 'Administration',100);


INSERT INTO DEPARTMENT VALUES (20, 'Marketing', 101);
INSERT INTO DEPARTMENT VALUES (30, 'Human Resources',102);
INSERT INTO DEPARTMENT VALUES (40, 'Operations',103);
INSERT INTO DEPARTMENT VALUES (50, 'Finance',104);
INSERT INTO DEPARTMENT VALUES (60, 'Accounts',105);
INSERT INTO DEPARTMENT VALUES (70, 'IT Support',NULL);
INSERT INTO DEPARTMENT VALUES (80, 'IT Helpdesk',NULL);
INSERT INTO DEPARTMENT VALUES (90, 'Executive',NULL);

INSERT INTO JOB VALUES (1, 'President', 20080, 40000);


INSERT INTO JOB VALUES (2, 'Vice President', 15000, 30000);
INSERT INTO JOB VALUES (3, 'Administrative Assistant', 3000, 6000);
INSERT INTO JOB VALUES (4, 'Finance Manager', 8200, 16000);
INSERT INTO JOB VALUES (5, 'Accountant', 4200, 9000);
INSERT INTO JOB VALUES (6, 'Manager', 8200, 16000);
INSERT INTO JOB VALUES (7, 'Software Engineer', 10000, 20080);
INSERT INTO JOB VALUES (8, 'Principal Engineer', 15000, 30000);
INSERT INTO JOB VALUES (9, 'Programmer', 5000, 10000);
INSERT INTO JOB VALUES (10, 'HR Representative', 4000, 9000);

INSERT INTO EMPLOYEE VALUES (100, 'Steven', NULL, 'King',


'sking','5151234567', '2003-06-17', 1, 24000, NULL, NULL, 10);
INSERT INTO EMPLOYEE VALUES (101, 'Neena', NULL, 'Kochhar',
'nkochhar','5151234440', '2005-09-21', 2, 21000, NULL, NULL, 20);
INSERT INTO EMPLOYEE VALUES (102, 'Lex', NULL, 'De Haan',
'ldehaan','5151234569', '2001-01-03', 2, 17500, NULL, NULL, 30);
INSERT INTO EMPLOYEE VALUES (103, 'Alaxander', NULL, 'Hunold',
'ahunold','5102234321', '2005-02-07', 3, 5000, NULL, NULL, 10);
INSERT INTO EMPLOYEE VALUES (104, 'Bruce', NULL, 'Ernest',
'bernest','5102234560', '2006-06-28', 4, 12000, NULL, NULL, 20);
INSERT INTO EMPLOYEE VALUES (105, 'David', NULL, 'Lorentz',
'dlorentz','5102234563', '2002-07-02', 5, 8000, NULL, NULL, 30);
INSERT INTO EMPLOYEE VALUES (106, 'Nancy', NULL, 'Greenberg',
'ngreenberg','5151234555', '2004-12-10', 6, 13500, NULL, NULL, 20);
INSERT INTO EMPLOYEE VALUES (107, 'Daniel', NULL, 'Faviet',
'dfaviet','5151244661', '2003-04-15', 3, 7500, NULL, NULL,30 );
INSERT INTO EMPLOYEE VALUES (108, 'John', NULL, 'Chen', 'jchen','5151244662',
'2001-11-13', 7, 11000, NULL, NULL, 10);
INSERT INTO EMPLOYEE VALUES (109, 'Luis', NULL, 'Popp', 'lpopp','5151244663',
'2002-03-18', 8, 27000, NULL, NULL, 20);

Screenshot:
Questions:
Q1: Add a GENDER field to the EMPLOYEE table and add constraints to check that
GENDER is in ('M', 'F', 'O')

Description: This query adds a new column GENDER to the EMPLOYEE table and ensures that
the values are restricted to 'M', 'F', or 'O'.
Query and Screenshots:
Q2: Add constraint in JOB table to check MAX_SALARY is greater or equal to
MIN_SALARY

Description: This query adds a constraint to the JOB table to ensure that the MAX_SALARY is
always greater than or equal to MIN_SALARY.

Query and Screenshots:


Q3: Add constraint in JOB_HISTORY table to check that END_DATE is greater than
START_DATE

Description: This query ensures that the END_DATE in the JOB_HISTORY table is always later
than the START_DATE.
Query and Screenshots:
Q4: Create an index in the EMPLOYEE table using EMPLOYEE_ID, DEPARTMENT_ID,
JOB_ID

Description: This query creates an index on the EMPLOYEE table to improve query performance
for searches based on EMPLOYEE_ID, DEPARTMENT_ID, and JOB_ID.

Query and Screenshot:

Q5: Create a view to display details about the employee

Description: This query creates a view named employee_details to display comprehensive details
about the employees, including full name, department, job title, etc.

Query and Screenshot:


Q6: Create a procedure to display the EMPLOYEE_ID, name, and annual salary of all the
employees

Description: This query creates a stored procedure to display the EMPLOYEE_ID, full name,
and annual salary of all employees.

Query and Screenshot:

Q7: Create a procedure to display the number of employees according to gender

Description: This query creates a stored procedure to count the number of employees based on
their gender.

Query and Screenshot:


Lab 2: Consider the following two tables and answer the following
questions. (Aggregation and Joins)

Objective: The objective of this lab is to practice SQL queries involving aggregation
functions and joins using two tables: CUSTOMERS and ORDERS.

1. Created a new database named "ADBMSLab2".


2. Created two tables: CUSTOMERS and ORDERS.
3. Inserted sample data into both tables.
Tasks and Solutions:

Task (a): Join CUSTOMERS and ORDERS tables using a SELECT statement.

Query and Output:

Task (b): Join CUSTOMERS and ORDERS tables using the SELECT statement.
Query and Output:

Task (c): Join CUSTOMERS and ORDERS tables using the SELECT statement.

Query and Output:


Task (d): Add a new column "SEX" in the CUSTOMERS table.

Query and Output:

Task (e): Drop the "SEX" column from the CUSTOMERS table.
Query and Output:
Task (f): Delete complete data from an existing table using the TRUNCATE TABLE
command and show the output:
Query and Output:

Task (g): Create a View "CUSTOMERS_VIEW" from CUSTOMERS table


selecting name and age.
Task(h): Display records where the similar age count is more than or equal to 2.

Query and Output:

Task(i): Delete records from the CUSTOMERS table where age is 25 and COMMIT
changes.
Query and Output:

Task(j): What is use of the ROLLBACK command? Write a ROLLBACK


command to undo the above operation (a)
The ROLLBACK command in SQL is used to undo transactions that have not yet been committed
to the database. It is crucial in maintaining data integrity and ensuring that database operations
can be reverted if errors occur or if transactions need to be canceled for any reason.

Query and Output:


LAB-3: Use the given HR Schema and answer the following
questions.

First Make Schemas and insert data into tables:


CREATE DATABASE aDBMSLab3;

USE aDBMSLab3;

CREATE TABLE regions (


region_id INT PRIMARY KEY,
region_name VARCHAR(50)
);

CREATE TABLE countries ( country_id


CHAR(2) PRIMARY KEY,
country_name VARCHAR(50),
region_id INT,
FOREIGN KEY (region_id) REFERENCES regions(region_id)
);
CREATE TABLE locations (
location_id INT PRIMARY KEY,
street_address VARCHAR(100),
postal_code VARCHAR(20), city
VARCHAR(50), state_province
VARCHAR(50), country_id
CHAR(2),
FOREIGN KEY (country_id) REFERENCES countries(country_id)
);

CREATE TABLE departments (


department_id INT PRIMARY
KEY, department_name
VARCHAR(50), location_id INT,
manager_id INT,
FOREIGN KEY (location_id) REFERENCES locations(location_id)
);

CREATE TABLE jobs ( job_id


VARCHAR(10) PRIMARY KEY,
job_title VARCHAR(50), min_salary
DECIMAL, max_salary DECIMAL
);

CREATE TABLE employees (


employee_id INT PRIMARY
KEY, first_name VARCHAR(50),
last_name VARCHAR(50), email
VARCHAR(100), phone_number
VARCHAR(20), hire_date DATE,
job_id VARCHAR(10), salary
DECIMAL, commission_pct
DECIMAL, manager_id INT,
department_id INT,
FOREIGN KEY (job_id) REFERENCES jobs(job_id),
FOREIGN KEY (manager_id) REFERENCES employees(employee_id), FOREIGN
KEY (department_id) REFERENCES departments(department_id)
);

CREATE TABLE job_history


( employee_id INT,
start_date DATE, end_date
DATE, job_id
VARCHAR(10),
department_id INT,
PRIMARY KEY (employee_id, start_date),
FOREIGN KEY (employee_id) REFERENCES employees(employee_id),
FOREIGN KEY (job_id) REFERENCES jobs(job_id),
FOREIGN KEY (department_id) REFERENCES departments(department_id)
);

-- Inserting data into regions


INSERT INTO regions (region_id, region_name) VALUES (1, 'Europe');
INSERT INTO regions (region_id, region_name) VALUES (2, 'Americas');
INSERT INTO regions (region_id, region_name) VALUES (3, 'Asia');

-- Inserting data into countries


INSERT INTO countries (country_id, country_name, region_id) VALUES ('US', 'United
States', 2);
INSERT INTO countries (country_id, country_name, region_id) VALUES ('IN', 'India', 3);
INSERT INTO countries (country_id, country_name, region_id) VALUES ('DE', 'Germany',
1);

-- Inserting data into locations


INSERT INTO locations (location_id, street_address, postal_code, city, state_province,
country_id)
VALUES (1000, '123 Main St', '12345', 'New York', 'NY', 'US');
INSERT INTO locations (location_id, street_address, postal_code, city, state_province,
country_id)
VALUES (1001, '456 Elm St', '67890', 'Berlin', 'Berlin', 'DE');
INSERT INTO locations (location_id, street_address, postal_code, city, state_province,
country_id)
VALUES (1002, '789 Oak St', '54321', 'Mumbai', 'MH', 'IN');
-- Inserting data into departments
INSERT INTO departments (department_id, department_name, location_id, manager_id)
VALUES (10, 'HR', 1000, NULL);
INSERT INTO departments (department_id, department_name, location_id, manager_id)
VALUES (20, 'IT', 1001, NULL);
INSERT INTO departments (department_id, department_name, location_id, manager_id)
VALUES (30, 'Finance', 1002, NULL);

-- Inserting data into jobs


INSERT INTO jobs (job_id, job_title, min_salary, max_salary)
VALUES ('J1', 'Manager', 5000, 10000);
INSERT INTO jobs (job_id, job_title, min_salary, max_salary)
VALUES ('J2', 'Developer', 3000, 8000);
INSERT INTO jobs (job_id, job_title, min_salary, max_salary)
VALUES ('J3', 'Analyst', 4000, 9000);

-- Inserting data into employees


INSERT INTO employees (employee_id, first_name, last_name, email, phone_number,
hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (1, 'John', 'Doe', '[email protected]', '123-456-7890', '2020-01-15', 'J1', 9000,
NULL, NULL, 10);
INSERT INTO employees (employee_id, first_name, last_name, email, phone_number,
hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (2, 'Jane', 'Smith', '[email protected]', '234-567-8901', '2019-03-20', 'J2',
7000, 0.10, 1, 20);
INSERT INTO employees (employee_id, first_name, last_name, email, phone_number,
hire_date, job_id, salary, commission_pct, manager_id, department_id)
VALUES (3, 'Sam', 'Brown', '[email protected]', '345-678-9012', '2021-06-25', 'J3',
6000, NULL, 1, 30);
-- Inserting data into job_history
INSERT INTO job_history (employee_id, start_date, end_date, job_id, department_id)
VALUES (1, '2018-01-01', '2019-12-31', 'J2', 20);
INSERT INTO job_history (employee_id, start_date, end_date, job_id, department_id)
VALUES (2, '2017-05-01', '2018-04-30', 'J3', 30);
INSERT INTO job_history (employee_id, start_date, end_date, job_id, department_id)
VALUES (3, '2019-08-01', '2020-07-31', 'J1', 10);
SQL Queries:

1. From the following tables, write a SQL query to find the first name, last name,

department number, and department name for each employee..

2. From the following tables, write a SQL query to display the department name,
city, and state province for each department.
3. From the following tables, write a SQL query to find the difference between the
maximum salary of the job and salary of the employees. Return job title, employee
name, and salary difference.

4. From the following table, write a SQL query to compute the average salary,
number of employees received commission in that department. Return
department name, average salary and number of employees in alphabetical order
of departments.

5. Write a SQL query that returns data about employees whose salaries exceed their
department average.
LAB-4: Practice DDLs and Queries
Note: Use Oracle LiveSQL to complete the assignments. Oracle LiveSQL

Objective:

The objective of this lab is to practice the creation of database objects such as types,
tables, and procedures in Oracle LiveSQL, and perform basic operations including
insertion and querying of data.

Steps Taken:

1. Declare Classes:
○ address_typ: Defined as an object type representing an address.

2. phone_typ: Defined as an object type representing phone numbers.


3. employee_typ4: Defined as an object type representing employee information includeing
address and member functions

4. define class body:


○ Defined member functions for the employee_typ4 type.

5. create object employee_table:


Created a table employee_table to store employee data using the employee_typ4 type.
6. insert records:

6. select records
LAB-5: Practice with Object Types and Collections in Oracle
LiveSQL

Title: Practice the Given DDLs and Queries

Introduction

This lab explores Object-Relational features in Oracle by defining object types and
manipulating them using SQL statements. The provided code creates a sample schema for
purchase orders, customers, and stock items. It then demonstrates queries to retrieve and
analyze data related to purchase orders.

Materials

● Oracle Live SQL (https://livesql.oracle.com/)

Lab Tasks

The provided code outlines several tasks achieved using Oracle Live SQL. Here's a
breakdown of each code snippet:

1. Object Type Definitions:


○ StockItem_objtyp: Defines the structure of a stock item, including
attributes like StockNo, Price, and TaxRate.
○ LineItem_objtyp: Defines the structure of a line item in a purchase order,
with attributes like LineItemNo, Stock_ref (a reference to a
StockItem_objtyp), Quantity, and Discount.
○ PurchaseOrder_objtyp: Defines the structure of a purchase order,
including attributes like PONo, Cust_ref (a reference to a
Customer_objtyp), OrderDate, ShipDate, LineItemList_ntab (a nested table
of LineItem_objtyp), and ShipToAddr_obj (an address object).
○ PhoneList_vartyp: Defines a varying array type to store phone numbers.
○ Address_objtyp: Defines the structure of an address with attributes like
Street, City, State, and Zip.
2. Creating Object Tables:
0 Customer_objtab: Stores instances of the Customer_objtyp object type. It
includes a primary key constraint on the Custno attribute.
○ Stock_objtab: Stores instances of the StockItem_objtyp object type. It
includes a primary key constraint on the StockNo attribute.
○ PurchaseOrder_objtab: Stores instances of the PurchaseOrder_objtyp
object type. It includes a primary key constraint on the PONo attribute and
a foreign key constraint referencing the Customer_objtab table.
3. Adding Scope for REF column:
0 The SCOPE FOR clause is added to the PoLine_ntab table to define the
scope of the Stock_ref column, specifying that it references the

4. Creating Index:
0 An index named Po_nidx is created on the NESTED_TABLE_ID column
of the PoLine_ntab table.
5. Inserting Sample Data:
0 Sample data is inserted into the Stock_objtab and Customer_objtab
tables.
SQL Worksheet & Clear - Find Actions ..., Save lil•I
93
94 v INSERT INTO Customer _obj tab VALUES (
95 2,
96 'John Nike',
97 Address_objtyp( '323 College Drive', 'Edison', 'NJ', '08820'),
98 PhoneList_vartyp('908-904-0940')
99 );
100
101 v INSERT INTO Pu rchaseOrde r _obj tab
102 SELECT
103 1001,
104 REF(C),
105 SYSDATE,
106 '10-MAY-1997',
107 LineitemList_ntabtyp(),
108 NULL
109 FROM
110 Customer_objtab C
111 WHERE
112 C.Custno = 1;

1 row(s) inserted.

1 row(s) inserted.

SQL Worksheet & Clear -- Find Actions ..., Save lii•I


113
114 v INSERT INTO PurchaseOrder_objtab
115 SELECT
116 2001,
117 REF(C),
118 SYSDATE,
119 '20-MAY-1997' ,
120 CAST(
121 MULTISET(
122 SELECT
123 01,
124 REF(S),
125 12,
126 0
127 FROM
128 Stock_objtab S
129 WHERE
130 S.StockNo = 1534
131 AS LineitemList_ntabtyp
132 ),
133 Address_objtyp( '55, Madison Ave', 'Madison', 'WI', '53715')
134 FROM
135 Customer_objtab C

136 WHERE
137 C.Custno = 2;
1-:rn

1 row(s) inserted.
6. Creating Member Functions and Procedures:
0 Member functions and procedures are definedfor the
PurchaseOrder_objtyp object type to perform various operations,
including calculating the total cost of line items (sumLineItems),
retrieving the purchase order number (getPONo), adding a new line item
(purchase_item), updating a line item (update_item), and displaying
Queries:

Several SQL queries are provided to retrieve specific information from the object tables,
such as line items and customer information for a purchase order, the total value of each
purchase order, line items and purchase numbers for specific stock items, and customer
phone numbers.
1. Retrieve Line Items and Customer Name for Each Purchase Order (2001):

2. Retrieve Total Value for Each Purchase Order:


3. Retrieve Line Items and Purchase Numbers for StockNo 1535:

4. Display Customer Phone Numbers:


Conclusion:
This Lab demonstrates the use of object-oriented features in Oracle, including user-
defined object types, object tables, nested tables, object references, member functions, and
procedures. These features allow developers to model complex data structures and
relationships in the database more effectively.
LAB-6: Practice the given queries (Triggers)

Step-by-Step Instructions

1. Create employee_salary Table

Create a table employee_salary with columns for employee ID, salary, and employee
name.

2. Create employee_salary_log Table

Create a table employee_salary_log to log salary updates, including columns for


employee ID, new salary, update date, and updated by.

3. Create Trigger trg_log_employee_salary


Create a trigger trg_log_employee_salary that will be executed after an update on the
SALARY column of the employee_salary table. This trigger will log the changes into the
employee_salary_log table.

4. Insert Data into employee_salary

Insert an employee record into the employee_salary table.


5. Select Data from employee_salary

Select all data from the employee_salary table to verify the insertion.

6. Update SALARY in employee_salary

Update the salary of the employee with EMP_ID 101.

7. Select Data from employee_salary

Select all data from the employee_salary table to verify the update.
8. Select Data from employee_salary_log

Select all data from the employee_salary_log table to verify the trigger execution and log
entry.

This completes the lab for practicing SQL queries involving triggers. Follow each step
carefully to ensure correct execution and logging of salary updates.
LAB-7: Indexing and Query Cost Analysis
Create 4/5 tables, use indexes and non-index columns, and verify the query cost for
such indexed and non-index columns inserting millions of records.

Objective
In this lab, we will:

● Create multiple tables.


● Use indexes and non-index columns.
● Insert millions of records.
● Verify the query cost for indexed and non-index columns.

Step-by-Step Instructions

Step 1: Create Tables

We will create four tables to simulate a larger database environment. The primary table is
verylargetable, and additional tables are large_table_2, large_table_3, and large_table_4.

Step 2: Insert Data

We will insert a large number of records into the verylargetable table using the all_objects
system view to generate data.
Step 3: Query Without Index

We will perform a query on the verylargetable table without an index and check the query
cost using the EXPLAIN PLAN statement.
PLAN_TABLE_OUTPUT
Plan hash value: 2814310728

I Id I Operation !Name I Rows I Bytes I Cost (%CPU)! Time I

I 0 I SELECT STATEMENT I I 1900 I 39760 I 36 (3)1 00:00:01 I


I* 1 I TABLE ACCESS FULL! VERYLARGETABLE I 1900 I 39760 I 36 (3)1 00:00:01 I

Predicate Information {identified by operation id):

1 - filter("FNAME" LIKE 'b_%')

Note

- dynamic statistics used: dynamic sampling (level=2)


Step 4: Create Index

Next, we create an index on the fname column in the verylargetable table.

Step 5: Query With Index

We perform the same query on the verylargetable table with the index and check the
query cost.
Typically, the query cost should be lower with the index, indicating a more efficient query
execution.

Conclusion
This lab demonstrates how indexing can significantly improve query performance by
reducing the query cost. The EXPLAIN PLAN statement helps in analyzing the execution
plans and understanding the impact of indexing on query efficiency.
LAB-8: NoSQL Database Simple Examples

Objective:

The objective of this lab is to demonstrate basic CRUD (Create, Read, Update, Delete)
operations using MongoDB.

Step 1: Create Account on MongoDB Atlas

Visit MongoDB Atlas and create a free account.


Step 2: Install MongoDB on Visual Studio Code

In Visual Studio Code, click the Extensions icon in the left navigation.

Procedure

1. Open the Extensions View.

In Visual Studio Code, click the Extensions icon in the left navigation.

2. Search "MongoDB for VS Code" in the extension marketplace.


3. Click Install on the "MongoDB for VS Code" extension.

Once the installation is complete, the Install button changes to the Manage gear
button.

Once you install MongoDB for VS Code, you can view data in your deployment
and create Playgrounds to interact with your data.

To know your connection string to connect to VScode:


● Click on Database which is below Deployment.
● Choose your cluster.
● Click on MongoDB for vscode

To Connect Cloud MongoDB to vscode:


● Click on the leaf icon as shown in figure below.
● Click on Create New Playground.
● Clock on Play icon on the right top.
● Click on Click here to change Connection as shown in figure[3].

● The top search bar will appear and click on Add new Connection.
● Paste your connection string there and don't forget to put your password in the
blurred section.

● Click Enter and you are connected to the remote mongoDB cluster.
Start MongoDB Shell:
● Open terminal in your VSCode and paste it:
○ brew install mongosh
● Run your connection string in your command line
Use this connection string in your application

Eg : mongosh "mongodb+srv://cluster0.or0jnhz.mongodb.net/" --apiVersion 1 --username

Enter your password, now you are connected via terminal.

To Run CRUD Operations:

Create or Switch to a Database:

use aDBMS_practice

Create a Collection:

db.createCollection('sales')

Insert Documents:

db.sales.insertMany([
{ '_id': 1, 'item': 'abc', 'price': 10, 'quantity': 2, 'date': new Date('2014-03-01T08:00:00Z') },
{ '_id': 2, 'item': 'jkl', 'price': 20, 'quantity': 1, 'date': new Date('2014-03-01T09:00:00Z') },
{ '_id': 3, 'item': 'xyz', 'price': 5, 'quantity': 10, 'date': new Date('2014-03-15T09:00:00Z') },
{ '_id': 4, 'item': 'xyz', 'price': 5, 'quantity': 20, 'date': new Date('2014-04-04T11:21:39.736Z') },
{ '_id': 5, 'item': 'abc', 'price': 10, 'quantity': 10, 'date': new Date('2014-04-04T21:23:13.331Z')
},
{ '_id': 6, 'item': 'def', 'price': 7.5, 'quantity': 5, 'date': new Date('2015-06-04T05:08:13Z') },
{ '_id': 7, 'item': 'def', 'price': 7.5, 'quantity': 10, 'date': new Date('2015-09-10T08:43:00Z') },
{ '_id': 8, 'item': 'abc', 'price': 10, 'quantity': 5, 'date': new Date('2016-02-06T20:20:13Z') }
])

Query Documents:
Update a Document:
db.sales.updateOne({ _id: 2 }, { $set: { item: 'abcdefg' } })
db.sales.find().pretty()
Delete a Document:
db.sales.deleteOne({ _id: 1 })

By following these steps and examples, basic CRUD operations can be performed using

MongoDB.
LAB-9: Object-Oriented Database Support in Oracle Database

Objective
In this lab, we explore the object-oriented database support in Oracle Database. We will
create user-defined types (UDTs) to represent complex data structures and use them in
tables. Additionally, we will define methods within the UDTs to encapsulate behavior.

Step-by-Step Instructions

Step 1: Create User-Defined Types (UDTs)

We define two object types (address_type and phone_type) to represent address and phone
number information, respectively. We also create the employee_type object type to
encapsulate employee data along with their address.
Step 2: Define Methods for UDTs

We define methods within the employee_type object type to encapsulate behavior. In this
case, we define get_idno() to return the employee ID and display_address() to display the
employee's address.

We create a table employee_table of type employee_type

Step 4: Insert Data


We insert data into the employee_table using the INSERT INTO ... VALUES statement.
Step 5: Query Data

Retrieve and display the data from the employee_table.

This PL/SQL block retrieves each record from the employee_table one by one using a
cursor loop, and then displays the details of each employee including their ID, name,
address, and phone number.

Conclusion
This lab demonstrates the usage of object-oriented database features in Oracle Database,
including the creation of user-defined types (UDTs), defining methods within UDTs, and
utilizing UDTs in tables. By encapsulating data and behavior within object types, Oracle
Database offers a more flexible and intuitive way to model complex data structures and
relationships.
LAB-10: Distributed Database Setup using Postgres DB

Objective:
The purpose of this lab is to set up a distributed database using PostgreSQL on Windows.
This involves installing PostgreSQL, configuring the server and client, and performing
basic data operations.

Step 1: Download PostgreSQL for windows

https://www.postgresql.org/download/windows/

Step 2: Install PostgreSQL


Step 3: Perform CRUD Opertaion

1. Creating database:
2. Listing all databases:

3. Dropping database:

4. Disconnecting all database:

You might also like