DBMS database

mail@pastecode.io avatar
unknown
sql
a year ago
3.0 kB
7
Indexable

create table branch(
    branchName varchar(100) primary key,
    branchCity varchar(100),
    assets varchar(100));

create table account(
    accountNumber varchar(100) primary key,
    branchName varchar(100),
    balance varchar(100));

create table customer(
    customerName varchar(100) primary key,
    customerStreet varchar(100),
    customerCity varchar(100));

create table loan(
    loanNumber varchar(100) primary key,
    branchName varchar(100),
    amount varchar(100));

create table depositor(
    customerName varchar(100),
    accountNumber varchar(100),
primary key(customerName, accountNumber));

create table borrower(
    customerName varchar(100),
    loanNumber varchar(100),
primary key(customerName, loanNumber));

 alter table account add foreign key (branchName) references branch(branchName);
 alter table depositor add foreign key (accountNumber) references account(accountNumber);
 alter table depositor add foreign key (customerName) references customer(customerName);
 alter table borrower add foreign key (customerName) references customer(customerName);
 alter table borrower add foreign key (loanNumber) references loan(loanNumber);
 alter table loan add foreign key (branchName) references branch(branchName);
 
 
 
 INSERT INTO branch
 VALUES ('Brighton', 'Brooklyn', '7100000'),
              ('Downtown', 'Brooklyn', '9000000'),
              ('Mianus', 'Horseneck', '400000'),
              ('North Town', 'Rye', '3700000'),
            ('Perryridge','Horseneck','1700000'),
            ('Pownal','Bennington','300000'),
         ('Redwood','Palo Alto', '2100000'),
         ('Round Hill','Horseneck','8000000');

INSERT INTO account
VALUES ('A-101', 'Downtown', '500'),
       ('A-102', 'Perryridge', '400'),
       ('A-201', 'Brighton', '900'),
       ('A-215', 'Mianus', '700'),
       ('A-217', 'Brighton', '750'),
       ('A-222', 'Redwood', '700'),
       ('A-305', 'Round Hill', '350');

INSERT INTO depositor
VALUES
      ('Hayes', 'A-102'),
      ('Johnson', 'A-101'),
      ('Johnson', 'A-201'),
      ('Jones', 'A-217'),
      ('Lindsay', 'A-222'),
      ('Smith', 'A-215'),
      ('Turner', 'A-305');

INSERT INTO loan
VALUES
      ('L-11', 'Round Hill', '900'),
      ('L-14', 'Downtown', '1500'),
      ('L-15', 'Perryridge', '1500'),
      ('L-16', 'Perryridge', '1300'),
      ('L-17', 'Downtown', '1000'),
      ('L-23', 'Redwood', '2000'),
      ('L-93', 'Mianus', '500');

INSERT INTO customer
VALUES  
    ('Adams','Spring','Pittsfield'),
	('Brooks','Senator','Brooklyn'),
	('Curry','North','Rye'),
	('Glenn','Sand Hill','Woodside'),
	('Green','Walnut','Stamford'),
	('Hayes','Main','Harrison'),
	('Johnson','Alma','Palo Alto'),
	('Jones','Main','Harrison'),
	('Lindsay','Park','Pittsfield'),
	('Smith','North','Rye'),
	('Turner','Putnam','Stamford'),
	('Williams','Nassau','Princeton');

INSERT INTO borrower
VALUES
  ('Adams', 'L-16'),
  ('Curry', 'L-93'),
  ('Hayes', 'L-15'),
  ('Jones', 'L-17'),
  ('Smith', 'L-11'),
  ('Smith', 'L-23'),
  ('Williams', 'L-17');