bhikas dbms 3 (1)
bhikas dbms 3 (1)
bhikas dbms 3 (1)
SQL QUERY:-
CREATE TABLE Account (
AccNo INT PRIMARY KEY,
BranchName VARCHAR(50),
Balance DECIMAL(10, 2)
);
CREATE TABLE Branch (
BranchName VARCHAR(50) PRIMARY KEY,
BranchCity VARCHAR(50),
Assets DECIMAL(15, 2)
);
CREATE TABLE Customer (
CustName VARCHAR(100) PRIMARY KEY,
CustStreet VARCHAR(100),
CustCity VARCHAR(50)
);
CREATE TABLE Depositer (
CustName VARCHAR(100),
AccNo INT,
PRIMARY KEY (CustName, AccNo),
FOREIGN KEY (CustName) REFERENCES Customer(CustName),
FOREIGN KEY (AccNo) REFERENCES Account(AccNo)
);
CREATE TABLE Loan (
LoanNo INT PRIMARY KEY,
BranchName VARCHAR(50),
Amount DECIMAL(10, 2),
FOREIGN KEY (BranchName) REFERENCES Branch(BranchName)
);
CREATE TABLE Borrower (
CustName VARCHAR(100),
LoanNo INT,
PRIMARY KEY (CustName, LoanNo),
FOREIGN KEY (CustName) REFERENCES Customer(CustName),
FOREIGN KEY (LoanNo) REFERENCES Loan(LoanNo)
);
INSERT INTO Branch (BranchName, BranchCity, Assets)
VALUES
('SBI Connaught Place', 'Delhi', 100000000),
('HDFC MG Road', 'Bangalore', 75000000);
1. SELECT
C.CustName,
D.AccNo,
B.LoanNo
FROM
Customer C
LEFT JOIN
Depositer D ON C.CustName = D.CustName
LEFT JOIN
Borrower B ON C.CustName = B.CustName;
2. SELECT
C.CustName
FROM
Customer C
INNER JOIN
Depositer D ON C.CustName = D.CustName
INNER JOIN
Borrower B ON C.CustName = B.CustName;
3. SELECT
C.CustName
FROM
Customer C
INNER JOIN
Depositer D ON C.CustName = D.CustName
WHERE
C.CustName NOT IN (SELECT CustName FROM Borrower);
4. SELECT
D.CustName
FROM
Depositer D
GROUP BY
D.CustName
HAVING
COUNT(D.AccNo) > 1;