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

Lab Assignment

The document outlines a lab assignment involving the creation and management of distributed databases with three tables: EMP, ASG, and PROJ. It includes SQL commands for creating these tables, inserting records, and querying project names and budgets based on location and budget ranges. The assignment is designed for a student named Mitushi, with a roll number of 2022UCD2143.

Uploaded by

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

Lab Assignment

The document outlines a lab assignment involving the creation and management of distributed databases with three tables: EMP, ASG, and PROJ. It includes SQL commands for creating these tables, inserting records, and querying project names and budgets based on location and budget ranges. The assignment is designed for a student named Mitushi, with a roll number of 2022UCD2143.

Uploaded by

Mitushi Singh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Lab Assignment-3 Distributed Databases

Name: MITUSHI
Roll no.: 2022UCD2143

-- Create EMP table


CREATE TABLE EMP (
ENO CHAR(2) PRIMARY KEY,
ENAME VARCHAR(20),
TITLE VARCHAR(20)
);

-- Create ASG table


CREATE TABLE ASG (
ENO CHAR(2),
PNO CHAR(2),
RESP VARCHAR(20),
DUR INT,
PRIMARY KEY (ENO, PNO),
FOREIGN KEY (ENO) REFERENCES EMP(ENO),
FOREIGN KEY (PNO) REFERENCES PROJ(PNO)
);

-- Create PROJ table


CREATE TABLE PROJ (
PNO CHAR(2) PRIMARY KEY,
PNAME VARCHAR(30),
BUDGET INT,
LOC VARCHAR(20));
-- Insert records into EMP table
INSERT INTO EMP (ENO, ENAME, TITLE) VALUES
('E1', 'J. Doe', 'Elect. Eng.'),
('E2', 'M. Smith', 'Syst. Anal.'),
('E3', 'A. Lee', 'Mech. Eng.'),
('E4', 'J. Miller', 'Programmer'),
('E5', 'B. Casey', 'Syst. Anal.'),
('E6', 'L. Chu', 'Elect. Eng.'),
('E7', 'R. Davis', 'Mech. Eng.'),
('E8', 'J. Jones', 'Syst. Anal.');

-- Insert records into ASG table


INSERT INTO ASG (ENO, PNO, RESP, DUR) VALUES
('E1', 'P1', 'Manager', 12),
('E2', 'P1', 'Analyst', 24),
('E2', 'P2', 'Analyst', 6),
('E3', 'P3', 'Consultant', 10),
('E3', 'P4', 'Engineer', 48),
('E4', 'P2', 'Programmer', 18),
('E5', 'P2', 'Manager', 24),
('E6', 'P4', 'Manager', 48),
('E7', 'P3', 'Engineer', 36),
('E8', 'P3', 'Manager', 40);

-- Insert records into PROJ table


INSERT INTO PROJ (PNO, PNAME, BUDGET, LOC) VALUES
('P1', 'Instrumentation', 150000, 'Montreal'),
('P2', 'Database Develop.', 135000, 'New York'),
('P3', 'CAD/CAM', 250000, 'New York'),
('P4', 'Maintenance', 310000, 'Paris');

-- Query 1: Find project names and budgets based on location for each site
-- Site 1: Montreal
SELECT PNAME, BUDGET
FROM PROJ
WHERE LOC = 'Montreal';

-- Site 2: New York


SELECT PNAME, BUDGET
FROM PROJ
WHERE LOC = 'New York';

-- Site 3: Paris
SELECT PNAME, BUDGET
FROM PROJ
WHERE LOC = 'Paris';

-- Query 2: Manage projects based on budget ranges across four sites


SELECT PNAME, BUDGET,
CASE
WHEN BUDGET <= 200000 THEN 'Site 1'
WHEN BUDGET BETWEEN 240000 AND 320000 THEN 'Site 2'
WHEN BUDGET BETWEEN 350000 AND 450000 THEN 'Site 3'
ELSE 'Site 4'
END AS Managed_Site
FROM PROJ;

You might also like