0% found this document useful (0 votes)
29 views35 pages

Dbms A5 - Merged

Uploaded by

yogov87946
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)
29 views35 pages

Dbms A5 - Merged

Uploaded by

yogov87946
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/ 35

ASSIGNMENT – 05

1. Create tables for Client, Product, and Salesman with the attributes given, implementing DDL
commands for specifying prime attributes, non-prime attributes, foreign keys, cardinalities, null
values, constraints etc. and the data types. Implement DDL commands for drop, alter on the tables
created.
2. Implement DML commands like populating the tables with data using insert command and
retrieving data using simple queries in SQL. (Application of select, update, delete etc.)

CLIENT_MASTER

CREATE TABLE CLIENT_MASTER(Client_no VARCHAR2(6) CHECK(Client_no LIKE'C%')


PRIMARY KEY,
Name VARCHAR2(20) NOT NULL,
City VARCHAR2(15),
Pincode NUMBER(8),
State VARCHAR2(15),
BalDue NUMBER(10,2)
);

DESC CLIENT_MASTER;

PRODUCT_MASTER

CREATE TABLE PRODUCT_MASTER(Product_no VARCHAR2(6) CHECK(Product_no LIKE


'P%')
PRIMARY KEY,
Description VARCHAR2(15) NOT NULL,
QTY_ON_Hand NUMBER(8) NOT NULL,
Sell_Price NUMBER(8,2) CHECK(Sell_Price>0) NOT NULL,
Cost_Price NUMBER(8,2) CHECK(Cost_Price>0) NOT NULL);

DESC PRODUCT_MASTER;
SALESMAN_MASTER
CREATE TABLE SALESMAN_MASTER(Salesman_no VARCHAR2(6) CHECK(Salesman_no
LIKE 'S%') PRIMARY KEY,
Salesman_name VARCHAR2(20) NOT NULL,
City VARCHAR(20) NOT NULL,
Pincode NUMBER(8) NOT NULL,
State VARCHAR(20) NOT NULL,
Sal_Amt NUMBER(8,2) CHECK(Sal_Amt>0) NOT NULL);

DESC SALESMAN_MASTER;

SALES_ORDER
CREATE TABLE SALES_ORDER(Order_no VARCHAR2(6) CHECK(Order_no LIKE 'O%')
PRIMARY KEY,
Client_no VARCHAR2(6) REFERENCES CLIENT_MASTER(Client_no) ON DELETE
CASCADE,
Order_date DATE,
Salesman_no VARCHAR2(6) REFERENCES SALESMAN_MASTER(Salesman_no) ON
DELETE CASCADE,
Dely_type char(1) default 'F' CHECK(Dely_type='P' OR Dely_type='F'),
Dely_date DATE);

DESC SALES_ORDER;
SALES_ORDER_DETAILS
CREATE TABLE SALES_ORDER_DETAILS(Order_no VARCHAR2(6) REFERENCES
SALES_ORDER(Order_no) ON DELETE CASCADE,
Product_no VARCHAR2(6) REFERENCES PRODUCT_MASTER(Product_no) ON DELETE
CASCADE,
Qty_disp NUMBER(8),
Product_rate NUMBER(10,2)
);

DESC SALES_ORDER_DETAILS;

Insert 5 records in each table

CLIENT_MASTER

INSERT INTO CLIENT_MASTER VALUES('C001','Ankush Poddar','Kolkata',700001,'West


Bengal',456);
INSERT INTO CLIENT_MASTER VALUES('C002','Prakash
Roy','Mumbai',700091,'Maharashtra',999);
INSERT INTO CLIENT_MASTER VALUES('C003','Vikas Malik','Kalyani',743145,'West
Bengal',258);
INSERT INTO CLIENT_MASTER VALUES('C004','Kusan Dey','Chennai',700501,'Tamil
Nadu',500);
INSERT INTO CLIENT_MASTER VALUES('C005','Achin
Bora','Bengaluru',700092,'Karnataka',777);
COMMIT;
PRODUCT_MASTER
INSERT INTO PRODUCT_MASTER VALUES('P001','TShirt',52,500,150);
INSERT INTO PRODUCT_MASTER VALUES('P002','Shirt',90,1200,600);
INSERT INTO PRODUCT_MASTER VALUES('P003','Trouser',30,1800,1000);
INSERT INTO PRODUCT_MASTER VALUES('P004','Shorts',200,200,50);
INSERT INTO PRODUCT_MASTER VALUES('P005','Top',36,900,400);
COMMIT;

SALESMAN_MASTER

INSERT INTO SALESMAN_MASTER VALUES('S001','Raj Dey','Kolkata',700001,'West


Bengal',1600);
INSERT INTO SALESMAN_MASTER VALUES('S002','Dipak
Mandi','Mumbai',700091,'Maharashtra',2400);
INSERT INTO SALESMAN_MASTER VALUES('S003','Achin Malik','Kalyani',743145,'West
Bengal',2000);
INSERT INTO SALESMAN_MASTER VALUES('S004','Arko Dey','Chennai',700501,'Tamil
Nadu',3600);
INSERT INTO SALESMAN_MASTER VALUES('S005','Vijay
Bora','Bengaluru',700092,'Karnataka',2900);
COMMIT;
SALES_ORDER

INSERT INTO SALES_ORDER VALUES('O001','C001','15-09-24','S001','F','21-09-24');


INSERT INTO SALES_ORDER VALUES('O002','C002','10-09-24','S002','P','15-09-24');
INSERT INTO SALES_ORDER VALUES('O003','C003','12-09-24','S003','P','16-09-24');
INSERT INTO SALES_ORDER VALUES('O004','C004','20-09-24','S004','F','26-09-24');
INSERT INTO SALES_ORDER VALUES('O005','C005','05-09-24','S005','F','10-09-24');
COMMIT;

SALES_ORDER_DETAILS

INSERT INTO SALES_ORDER_DETAILS VALUES('O001','P001',52,621.33);


INSERT INTO SALES_ORDER_DETAILS VALUES('O002','P002',200,763);
INSERT INTO SALES_ORDER_DETAILS VALUES('O003','P003',400,227.9);
INSERT INTO SALES_ORDER_DETAILS VALUES('O004','P004',500,397);
INSERT INTO SALES_ORDER_DETAILS VALUES('O005','P005',600,321.29);
COMMIT;
Answer the following queries:

Exercise on retrieving records from a table


1. Find out the names of all clients.

Query: SELECT Name FROM CLIENT_MASTER;

2. Retrieve the entire contents of the Client_Master table.

Query: SELECT *FROM CLIENT_MASTER;


3. Retrieve the list of names, city and state of all clients.

Query: SELECT Name,City,State FROM CLIENT_MASTER;

4. List the various products available from the Product_Master table.

Query: SELECT Description FROM PRODUCT_MASTER;

5. List all clients who are located in Mumbai.

Query: SELECT *FROM CLIENT_MASTER WHERE City='Mumbai';

6. Find the names of salesman who have a salary equal to 3600.

Query: SELECT SALESMAN_NAME FROM SALESMAN_MASTER WHERE


SAL_AMT='3600';
7. Show the details of Product_Master according to Cost_Price in descending order.

Query: SELECT *FROM PRODUCT_MASTER ORDER BY COST_PRICE DESC;

8. Show different types of salary amounts of the salesman

Query: SELECT SAL_AMT FROM SALESMAN_MASTER;

9. Show only unique product details.

Query: SELECT DISTINCT DESCRIPTION FROM PRODUCT_MASTER;

Exercise on updating records in a table:


i. Change the city of client no ‘C001’ to ‘Bangalore’.

QUERY: UPDATE CLIENT_MASTER SET CITY='BANGALORE' WHERE Client_no='C001';


ii. Change the BalDue of client no ‘C005’ to Rs. 1000.

QUERY: UPDATE CLIENT_MASTER SET BALDUE=1000 WHERE Client_no='C005';


iii. Change the cost price of ‘Trouser’ to Rs. 950.00.

QUERY: UPDATE PRODUCT_MASTER SET Cost_Price=950.00 WHERE


Description='Trouser';

iv. Change the city of the salesman to ‘Pune’.

QUERY: UPDATE SALESMAN_MASTER SET CITY='PUNE' WHERE Salesman_no='S003';

v. Add a column called ‘Telephone’ of data type number and size = 10 to the Client_Master table.

QUERY: ALTER TABLE CLIENT_MASTER ADD (TELEPHONE NUMBER(10));


vi. Change the size of Sell_Price column in Product_Master to 10, 2.

QUERY: ALTER TABLE PRODUCT_MASTER Modify(Sell_Price Number(10,2));

vii. Drop the column Cost_Price from Product_Master.

QUERY: ALTER TABLE PRODUCT_MASTER DROP COLUMN COST_PRICE;


viii. Delete all salesmen from the Salesman_Master whose salaries are equal to Rs. 2400.

QUERY: delete from SALES_ORDER_DETAILS where Order_no='O004';


delete from SALES_ORDER where Client_no='C004';
delete from SALESMAN_MASTER where Sal_Amt=2400;

ix. Delete all products from Product_Master where the quantity on hand is equal to 90.

QUERY: DELETE PRODUCT_MASTER WHERE QTY_ON_HAND=90;

x. Delete from Client_Master where the column state holds the value ‘Maharashtra’.

QUERY: DELETE FROM CLIENT_MASTER WHERE STATE='Maharashtra';


xi. Change the name of the Salesman_Master table to Sman_Mast.

QUERY: ALTER TABLE SALESMAN_MASTER rename to Sman_Mast;

xii. Destroy the table Client_Master along with its data.

QUERY: DROP TABLE SALES_ORDER_DETAILS;


DROP TABLE SALES_ORDER;
DROP TABLE CLIENT_MASTER;
ASSIGNMENT 6.1

1. List the names of all clients having ‘A’ as the third letter in their names.
Query: SELECT NAME FROM CLIENT_MASTER WHERE NAME LIKE '__a%';

2. List the clients who stay in a city whose first letter is ‘K’
Query: SELECT *FROM CLIENT_MASTER WHERE CITY LIKE '%K%';

3. List all the clients who stay in ‘Mumbai’ or ‘Kolkata’


Query: SELECT *FROM CLIENT_MASTER WHERE CITY LIKE '%Kolkata%' OR CITY
LIKE'%Mumbai%';
4. List all the clients whose BalDue is greater than value 500
Query: SELECT *FROM CLIENT_MASTER WHERE BALDUE>500;

5. List all information from the Sales_Order table for orders placed in the month of June.
Query: SELECT *FROM SALES_ORDER WHERE ORDER_DATE LIKE '%-06-%';

6. List the order information for Client_no ‘C001’ and ‘C003’.


Query: SELECT *FROM SALES_ORDER WHERE CLIENT_NO IN('C001','C003');

7. List products whose selling price is greater than 500 and less than or equal to 750.
Query: SELECT *FROM PRODUCT_MASTER WHERE SELL_PRICE>500 AND
SELL_PRICE<=750;
8. Count the total number of order.
Query: SELECT COUNT(ORDER_NO) FROM SALES_ORDER_DETAILS;

9. Determine the maximum and minimum product prices. Rename the output as max_price and
min_price respectively.
Query: SELECT MIN(SELL_PRICE) “MIN_PRICE”, MAX(SELL_PRICE) “MAX_PRICE”
FROM PRODUCT_MASTER;

10. Count the number of client who live in Kolkata.


Query: SELECT COUNT(CLIENT_NO) FROM CLIENT_MASTER WHERE CITY='Kolkata';

11. Count the number of products having price less than or equal to 500.
Query: SELECT COUNT(PRODUCT_NO) FROM PRODUCT_MASTER WHERE
COST_PRICE<=500;
12. List the order number and day on which clients placed their order.
Query: SELECT ORDER_NO, TO_CHAR(TO_DATE(ORDER_DATE,'DD-MM-YY'),'Month')
AS MONTHNAME FROM SALES_ORDER;

13. List the Order_Date in the format ‘DD-Month-YY’.


Query: SELECT TO_CHAR(ORDER_DATE,'DD-Month-YY') AS FORMATTED_DATE
FROM SALES_ORDER;

14. List the date, 20 days after today’s date.


Query: SELECT SYSDATE+20 FROM DUAL;
15. List name of the client who has maximum BalDue.
Query: SELECT NAME FROM CLIENT_MASTER WHERE BALDUE=(SELECT
MAX(BALDUE) FROM CLIENT_MASTER);

16. Find the difference between maximum BalDue and minimum BalDue.
Query: SELECT MAX(BALDUE)-MIN(BALDUE) FROM CLIENT_MASTER;

17. Add Rs.1000/- with the salary amount of every salesmen.


Query: UPDATE SALESMAN_MASTER SET SAL_AMT=SAL_AMT+1000;
ASSIGNMENT 6.2
Create tables for Employee, Company and works and populate them. Retrieve data by writing nested
queries in SQL using JOIN to combine tables and other operators like IN, BETWEEN, LIKE etc.

Employee:

CREATE TABLE Employee(


Emp_no VARCHAR2(6) CHECK(Emp_no LIKE 'E%') PRIMARY KEY,
Name VARCHAR2(20) NOT NULL,
DOB DATE,
Sex CHAR(1),
Address VARCHAR2(20),
BalDue NUMBER(10)
);

DESC Employee;

Company:

Create TABLE Company(


comp_no VARCHAR2(6) CHECK(comp_no LIKE 'C%') PRIMARY KEY,
Name VARCHAR2(20) NOT NULL,
Address VARCHAR2(20)
);

DESC Company;
Works:

Create TABLE Works(


Emp_no VARCHAR2(6) REFERENCES Employee(Emp_no) ON DELETE CASCADE,
comp_no VARCHAR2(6) REFERENCES Company(comp_no) ON DELETE CASCADE
);

DESC Works;

Insert 5 records in each table:

Employee:
INSERT INTO Employee VALUES('E00001','Ankush','12-10-2002','M','Kanchrapara',15000);
INSERT INTO Employee VALUES('E00002','Asha','22-10-2012','F','Kalyani',25000);
INSERT INTO Employee VALUES('E00003','Ronaldo','12-09-2003','M','Saltlake',20000);
INSERT INTO Employee VALUES('E00004','Rocky','29-03-2015','M','Esplanade',35000);
INSERT INTO Employee VALUES('E00005','Sneha','21-06-1999','F','Barrackpore',55000);
COMMIT;

Company:
INSERT INTO Company VALUES('C00001','Clifford Corp','Kolkata');
INSERT INTO Company VALUES('C00002','Edmond Corp','Mumbai');
INSERT INTO Company VALUES('C00003','Wipro','Bengalore');
INSERT INTO Company VALUES('C00004','TCS','Bengalore');
INSERT INTO Company VALUES('C00005','Mahindra','Kolkata');
COMMIT;
Works:

INSERT INTO Works VALUES('E00001','C00001');


INSERT INTO Works VALUES('E00002','C00002');
INSERT INTO Works VALUES('E00003','C00003');
INSERT INTO Works VALUES('E00004','C00004');
INSERT INTO Works VALUES('E00005','C00005');
COMMIT;

1. List the employees who work for company ‘C00002’

Query: SELECT Employee.Name


FROM Employee
JOIN Works ON Employee.emp_no=Works.emp_no
WHERE Works.comp_no='C00002';
2. List the employees who work for company ‘C00004’

Query: SELECT Employee.Name


FROM Employee
JOIN Works ON Employee.emp_no=Works.emp_no
WHERE Works.comp_no='C00004';

3. List the employees who work for Clifford Corp.

Query: SELECT Employee.Name


FROM Employee
JOIN Works ON Employee.emp_no=Works.emp_no
JOIN Company ON Works.comp_no=Company.comp_no
WHERE Company.name='Clifford Corp';

4. List the employees whose name ends with ‘a’

Query: SELECT Name FROM Employee WHERE name like '%a';


5. List the employees born between 1999 and 2011

Query: SELECT Name FROM Employee WHERE DOB BETWEEN '01-01-1999' AND '31-12-
2011';
Software Requirements
Specification
for

Online Library
Management System
Version 1.0 approved
Prepared by Ankush Poddar

CSBS, Techno Main Salt Lake

16.09.2024

1 | Page
Contents
1 Functional Requirements ..........................................................................................................3
1.1 Greetings............................................................................................................................3
1.2 User Authentication ...........................................................................................................3
1.2.1 Username and Password Verification ........................................................................3
1.2.2 Forgot Password .........................................................................................................3
1.3 Book Management .............................................................................................................3
1.3.1 Search for Books ........................................................................................................3
1.3.2 Book Reservation .......................................................................................................4
1.3.3 Book Checkout ...........................................................................................................4
1.3.4 Book Return ...............................................................................................................4
1.3.5 View Borrowed Books ...............................................................................................4
1.3.6 Fine Payment ..............................................................................................................4
1.3.7 Update Personal Information......................................................................................4
1.3.8 Book Recommendation ..............................................................................................5
1.3.9 Review and Rate Books .............................................................................................5

2 | Page
1 Functional Requirements

1.1 Greetings
• Description: A greeting message appears on the screen when a user accesses the online
library management system, acknowledging the user’s access.
• Output: Welcome message with the name and logo of the library.
• Error: System temporarily out of service.

1.2 User Authentication

1.2.1 Username and Password Verification

• Description: The user enters a username and password to log in to the system.
• Input: User needs to input their username and password in the designated fields.
• Output: Verified successfully, user gains access to the system.
• Error: Invalid username or password, account locked after multiple failed attempts.

1.2.2 Forgot Password

• Description: The user requests to reset the password by providing their registered email
or phone number.
• Input: User needs to input the registered email or phone number.
• Output: Password reset link sent to the email or OTP sent to the phone.
• Error: Invalid email or phone number.

1.3 Book Management

1.3.1 Search for Books

• Description: The user searches for books available in the library's catalog.
• Input: User enters the book title, author name, ISBN, or keywords in the search bar.
• Output: A list of books matching the search criteria is displayed.
• Error: No books found matching the search criteria.

3 | Page
1.3.2 Book Reservation

• Description: The user wants to reserve a book that is currently checked out by another
user.
• Input: User selects the book they wish to reserve.
• Output: Reservation confirmation is displayed, and an email notification is sent.
• Error: Book already reserved by another user.

1.3.3 Book Checkout

• Description: The user wants to check out a book from the library.
• Input: User selects the book for checkout and confirms the action.
• Output: Checkout confirmation is displayed, and due date information is provided.
• Error: Book unavailable or user's account has overdue books.

1.3.4 Book Return

• Description: The user returns a book to the library.


• Input: User confirms the book return through the online portal.
• Output: Return confirmation is displayed, and the account is updated.
• Error: No record of the book being checked out by the user.

1.3.5 View Borrowed Books

• Description: The user wants to view a list of all books currently borrowed.
• Input: No input required beyond logging into the system.
• Output: A list of borrowed books with due dates is displayed.
• Error: No books currently borrowed.

1.3.6 Fine Payment

• Description: The user pays any overdue fines through the online system.
• Input: User selects the option to pay fines and enters payment details.
• Output: Payment confirmation is displayed, and an email receipt is sent.
• Error: Invalid payment information, or payment gateway error.

1.3.7 Update Personal Information

• Description: The user updates their personal information, such as address, phone
number, or email.
• Input: User enters the new information in the appropriate fields.
• Output: Confirmation of successful update.
• Error: Invalid input or system error.

4 | Page
1.3.8 Book Recommendation

• Description: The user can recommend books for the library to acquire.
• Input: User enters book details (title, author, ISBN) and submits a recommendation.
• Output: Confirmation message of the recommendation being submitted.
• Error: Recommendation could not be submitted due to system error.

1.3.9 Review and Rate Books

• Description: The user can review and rate books they have read.
• Input: User selects the book, enters a review, and assigns a rating.
• Output: Review and rating are successfully posted on the book's page.
• Error: Review could not be posted due to system error.

5 | Page
DFD Level 0 for the Online Library Management System
DFD Level 0 for the ATM System
UDP MULTI-CLIENT
Q. WAP to implement UDP mult-iclient in C. Every client will send some word to server and the
server will return the corresponding cipher text. Clients will print the cipher text.

Client:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#define PORT 8080
#define BUF_SIZE 1024
int main() {
int sockfd;
struct sockaddr_in servaddr;
char buffer[BUF_SIZE];
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("Socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
servaddr.sin_port = htons(PORT);
while (1) {
printf("Enter a word to send to the server: ");
fgets(buffer, BUF_SIZE, stdin);
buffer[strcspn(buffer, "\n")] = 0;

sendto(sockfd, (const char *)buffer, strlen(buffer), MSG_CONFIRM, (const struct sockaddr


*)&servaddr, sizeof(servaddr));
int n = recvfrom(sockfd, (char *)buffer, BUF_SIZE, MSG_WAITALL, NULL, NULL);
buffer[n] = '\0';
printf("Cipher text received: %s\n", buffer);
}
close(sockfd);
return 0;
}

Server:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#define PORT 8080
#define BUF_SIZE 1024
void caesar_cipher(char *text, int shift) {
for (int i = 0; text[i] != '\0'; i++) {
char c = text[i];
if (c >= 'a' && c <= 'z') {
text[i] = (c - 'a' + shift) % 26 + 'a';
} else if (c >= 'A' && c <= 'Z') {
text[i] = (c - 'A' + shift) % 26 + 'A';
}
}
}

int main() {
int sockfd;
struct sockaddr_in servaddr, cliaddr;
char buffer[BUF_SIZE];
socklen_t len;

if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {


perror("Socket creation failed");
exit(EXIT_FAILURE);
}
memset(&servaddr, 0, sizeof(servaddr));
memset(&cliaddr, 0, sizeof(cliaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(PORT);
if (bind(sockfd, (const struct sockaddr *)&servaddr, sizeof(servaddr)) < 0) {
perror("Bind failed");
close(sockfd);
exit(EXIT_FAILURE);
}
printf("Server is waiting for messages...\n");
while (1) {
len = sizeof(cliaddr);
int n = recvfrom(sockfd, (char *)buffer, BUF_SIZE, MSG_WAITALL, (struct sockaddr
*)&cliaddr, &len);
buffer[n] = '\0';
printf("Received message: %s\n", buffer);
caesar_cipher(buffer, 3);
sendto(sockfd, (const char *)buffer, strlen(buffer), MSG_CONFIRM, (const struct
sockaddr *)&cliaddr, len);
printf("Cipher text sent: %s\n", buffer);
}
close(sockfd);
return 0;
}

You might also like