创建表结构及数据

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

/* clean up old tables;

must drop tables with foreign keys first due to referential integrity constraints */

delete from depositor;

drop table depositor;

delete from borrower;

drop table borrower;

delete from account;

drop table account;

delete from branch;

drop table branch;

delete from loan;

drop table loan;

delete from customer;

drop table customer;

create table branch

(branch_name varchar(15) not null unique,

branch_city varchar(15) not null,

assets numeric not null,

primary key(branch_name));

create table account

(account_number varchar(15) not null unique, branch_name varchar(15) not null,

balance numeric not null,

primary key(account_number));

create table customer

(customer_name varchar(15) not null unique, customer_street varchar(12) not null,

customer_city varchar(15) not null,

primary key(customer_name));

create table loan

(loan_number varchar(15) not null unique,

branch_name varchar(15) not null,

amount numeric not null,

primary key(loan_number));

create table depositor

(customer_name varchar(15) not null,

account_number varchar(15) not null,

primary key(customer_name, account_number),

foreign key(account_number) references account(account_number), foreign key(customer_name) references customer(customer_name));

create table borrower

(customer_name varchar(15) not null,

loan_number varchar(15) not null,

primary key(customer_name, loan_number),

foreign key(customer_name) references customer(customer_name), foreign key(loan_number) references loan(loan_number));

/* populate relations */

insert into customer values ('Jones', 'Main', 'Harrison'); insert into customer values ('Smith', 'Main', 'Rye'); insert into customer values ('Hayes', 'Main', 'Harrison');

insert into customer values ('Curry', 'North', 'Rye');

insert into customer values ('Lindsay', 'Park', 'Pittsfield');

insert into customer values ('Turner', 'Putnam', 'Stamford');

insert into customer values ('Williams', 'Nassau', 'Princeton');

insert into customer values ('Adams', 'Spring', 'Pittsfield');

insert into customer values ('Johnson', 'Alma', 'Palo Alto');

insert into customer values ('Glenn', 'Sand Hill', 'Woodside');

insert into customer values ('Brooks', 'Senator', 'Brooklyn');

insert into customer values ('Green', 'Walnut', 'Stamford');

insert into customer values ('Jackson', 'University', 'Salt Lake');

insert into customer values ('Majeris', 'First', 'Rye');

insert into customer values ('McBride', 'Safety', 'Rye');

insert into branch values ('Downtown', 'Brooklyn', 900000);

insert into branch values ('Redwood', 'Palo Alto', 2100000);

insert into branch values ('Perryridge', 'Horseneck', 1700000);

insert into branch values ('Mianus', 'Horseneck', 400200);

insert into branch values ('Round Hill', 'Horseneck', 8000000);

insert into branch values ('Pownal', 'Bennington', 400000);

insert into branch values ('North Town', 'Rye', 3700000); insert into branch values ('Brighton', 'Brooklyn', 7000000);

insert into branch values ('Central', 'Rye', 400280);

相关文档
最新文档