Moved Assignment-A2,A3 handout from handouts folder to Practical under the Assignment-A2,A3 folder respectively. Also added database queries for building Database_A2, need to add 'running queries'. Lastly, updated README.

This commit is contained in:
K 2024-07-25 12:41:40 +05:30
parent 13396f0977
commit 5043963095
Signed by: notkshitij
GPG Key ID: C5B8BC7530F8F43F
4 changed files with 96 additions and 3 deletions

View File

@ -0,0 +1,91 @@
# Queries for Assignment-A2
This file contains all the queries required to build the [database](https://git.kska.io/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2/Database_A2.sql)
## Creating database
```sql
CREATE DATABASE Database_A2;
USE Database_A2;
```
## Creating tables and specify primary keys:
```sql
CREATE TABLE Account(accountNum INT, branchName VARCHAR(50), balance INT, PRIMARY KEY (accountNum));
CREATE TABLE Branch(branchName VARCHAR(50), branchCity VARCHAR(50), assets INT, PRIMARY KEY (branchName));
CREATE TABLE Customer (customerName VARCHAR(50), customerStreet VARCHAR(50), customerCity VARCHAR(50), PRIMARY KEY (customerName));
CREATE TABLE Depositor (customerName VARCHAR(50), accountNum INT);
CREATE TABLE Loan (loanNum INT, branchName VARCHAR(50), amount INT, PRIMARY KEY (loanNum));
CREATE TABLE Borrower (customerName VARCHAR(50), loanNum INT);
```
## Altering tables to specify foreign keys
```sql
ALTER TABLE Account ADD FOREIGN KEY (branchName) REFERENCES Branch(branchName);
ALTER TABLE Depositor ADD FOREIGN KEY (customerName) REFERENCES Customer (customerName);
ALTER TABLE Depositor ADD FOREIGN KEY (accountNum) REFERENCES Account (accountNum);
ALTER TABLE Loan ADD FOREIGN KEY (branchName) REFERENCES Branch (branchName);
ALTER TABLE Borrower ADD FOREIGN KEY (customerName) REFERENCES Customer (customerName);
ALTER TABLE Borrower ADD FOREIGN KEY (loanNum) REFERENCES Loan (loanNum);
```
## Adding data
```sql
INSERT INTO Branch (branchName, branchCity, assets) VALUES
("Dhole Patil", "Kharadi", 50000),
("Nagarwala", "Akurdi", 20000),
("Peachtree", "Wakad", 35000),
("Bishops", "Nigdi", 10000),
("Amanora", "Hadapsar", 60000);
INSERT INTO Customer (customerName, customerStreet, customerCity) VALUES
("Kalas", "Airport Road", "Pune"),
("Mehul", "Shahdha", "Nandurbar"),
("Tanmay", "Porwal Road", "Pune"),
("Kshitij", "Hadapasar", "Pune"),
("Aditya", "Mira RD", "Mumbai"),
("Himanshu", "Smart City", "Nandurbar");
INSERT INTO Account (accountNum, branchName, balance) VALUES
(2501, "Dhole Patil", 5000),
(2511, "Nagarwala", 1500),
(2521, "Peachtree", 2000),
(2512, "Bishops", 5000),
(2531, "Amanora", 1000);
INSERT INTO Loan (loanNum, branchName, amount) VALUES
(155, "Dhole Patil", 500),
(156, "Nagarwala", 250),
(157, "Peachtree", 600),
(158, "Bishops", 900),
(159, "Amanora", 2500);
INSERT INTO Borrower VALUES
("Kalas", 156),
("Mehul", 158),
("Tanmay", 155),
("Kshitij", 157),
("Aditya", 159),
("Himanshu", 158);
INSERT INTO Depositor VALUES
("Kalas", 2511),
("Mehul", 2512),
("Tanmay", 2501),
("Kshitij", 2521),
("Aditya", 2531),
("Himanshu", 2512);
```
---
## Running queries
==PENDING==

View File

@ -10,9 +10,11 @@ A one-stop Git repository for third year SPPU Computer Engineering students foll
1. [Unit 1 - Introduction to Database Management Systems and ER Model](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Notes/Unit%201)
### Handouts
### Practical
1. [Assignment-A2](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Handouts/Assignment-A2.pdf)
2. [Assignment-A3](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Handouts/Assignment-A3.pdf)
> Each folder contains **handout**, **write-up** and **database**.
1. [Assignment-A2](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A2)
2. [Assignment-A3](https://git.kska.io/sppu-te-comp-content/DatabaseManagementSystems/src/branch/main/Practical/Assignment-A3)
---