0% found this document useful (0 votes)
4 views

db exp

The document outlines three experiments involving SQL and Java programming. Experiment 11 demonstrates creating and updating views in SQL with a focus on student marks. Experiment 10 integrates foreign keys in database tables for customers and orders, while Experiment 12 implements a Java program for dense and sparse indexing of an array.

Uploaded by

A K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

db exp

The document outlines three experiments involving SQL and Java programming. Experiment 11 demonstrates creating and updating views in SQL with a focus on student marks. Experiment 10 integrates foreign keys in database tables for customers and orders, while Experiment 12 implements a Java program for dense and sparse indexing of an array.

Uploaded by

A K
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Experiment No:11

Que-Create and update the views.


• Create Views-:

CREATE TABLE StudentMarks (ID INT PRIMARY KEY,NAME VARCHAR(255),Marks INT,Age INT);
INSERT INTO StudentMarks (ID, NAME, Marks, Age)VALUES(1, 'Harsh', 90, 19);
INSERT INTO StudentMarks (ID, NAME, Marks, Age)VALUES(2, 'Suresh', 50, 20);
INSERT INTO StudentMarks (ID, NAME, Marks, Age)VALUES(3, 'Pratik', 80, 19);
INSERT INTO StudentMarks (ID, NAME, Marks, Age)VALUES(4, 'Dhanraj', 95, 21);
INSERT INTO StudentMarks (ID, NAME, Marks, Age)VALUES(5, 'Ram', 85, 18);

select *from StudentMarks;

CREATE VIEW StudentView AS


SELECT ID, NAME,Marks
FROM StudentMarks
ORDER BY NAME;

SELECT * FROM StudentView;


Update views-:

UPDATE StudentView
SET Marks=96
where ID in (3,5);
select *from StudentView;

UPDATE StudentView
SET Marks = Marks*0.95;
Experiment NO-10

Que-Integrate of foreign key.


• CUSTOMERS1 Table
CREATE TABLE CUSTOMERS1 (id INT,first_name VARCHAR(40),Last_name VARCHAR(40),age
INT,country VARCHAR(10),CONSTRAINT CustomersPK PRIMARY KEY (id));
INSERT INTO CUSTOMERS1 VALUES(1, 'John', 'Doe', 31, 'USA');
INSERT INTO CUSTOMERS1 VALUES(2, 'Robert', 'Luna', 22, 'USA');
SELECT *FROM CUSTOMERS1;

• Orders Table
CREATE TABLE Orders ( order_id INT, product VARCHAR(40), total INT, customer_id INT,
CONSTRAINT OrdersPK PRIMARY KEY (order_id), FOREIGN KEY (customer_id) REFERENCES
Customers(id));
INSERT INTO Orders VALUES(1, 'Keyboard', 400, 2);
INSERT INTO Orders VALUES(2, 'Mouse', 300, 2);
INSERT INTO Orders VALUES(3, 'Monitor', 12000, 1);
SELECT *FROM Orders;
Experiment No-12
Que-Implement a java program for dense and sparse indexing.
import java.util.HashMap;
import java.util.Map;
import java.util.Arrays;

class Indexing {
private int[] data;
private Map<Integer, Integer> denseIndex;
private Map<Integer, Integer> sparseIndex;
private int sparseInterval;

public Indexing(int[] data, int sparseInterval) {


this.data = Arrays.copyOf(data, data.length);
this.denseIndex = new HashMap<>();
this.sparseIndex = new HashMap<>();
this.sparseInterval = sparseInterval;
createIndexes();
}
private void createIndexes() {
for (int i = 0; i < data.length; i++) {
denseIndex.put(data[i], i);
if (i % sparseInterval == 0) {
sparseIndex.put(data[i], i);
}
}
}
public int searchWithDenseIndex(int key) {
return denseIndex.getOrDefault(key, -1);
}

public int searchWithSparseIndex(int key) {


if (sparseIndex.containsKey(key)) {
return sparseIndex.get(key);
}
int lowerBoundKey = -1;
int lowerBoundIndex = -1;
for (Map.Entry<Integer, Integer> entry : sparseIndex.entrySet()) {
int currentKey = entry.getKey();
int currentIndex = entry.getValue();
if (currentKey < key && currentKey > lowerBoundKey) {
lowerBoundKey = currentKey;
lowerBoundIndex = currentIndex;
}
}
if (lowerBoundIndex != -1) {
for(int i = lowerBoundIndex + 1; i < lowerBoundIndex + sparseInterval && i <
data.length; i++){
if(data[i] == key){
return i;
}
}
}

return -1;
}

public static void main(String[] args) {


int[] data = {10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120};
int sparseInterval = 3;
Indexing indexExample = new Indexing(data, sparseInterval);

System.out.println("Dense Index Search:");


System.out.println("Index of 60: " + indexExample.searchWithDenseIndex(60));
System.out.println("Index of 15: " + indexExample.searchWithDenseIndex(15));

System.out.println("Sparse Index Search:");


System.out.println("Index of 70: " + indexExample.searchWithSparseIndex(70));
System.out.println("Index of 15: " + indexExample.searchWithSparseIndex(15));
}
}

You might also like