主キーと外部キーを持つテーブルが複数あるデータベースを作ってみたよ。
create table Users (
userId char(20),
userName char(20),
password char(20),
corpName char(100),
corpAddr char(100),
corpTel char(20),
corpFax char(20),
userMail char(50),
customerFlg char(5) default 'false',
PRIMARY KEY(userId)
);
insert into Users (
userId,
userName,
password,
corpName,
corpAddr,
corpTel,
corpFax,
userMail
) values (
'admin',
'Administrator',
'password',
'Hechigo Hall',
'Otani-ward, Tokyo',
'03-0000-0000',
'03-0000-0001',
'admin@hechigohall.co.jp'
);
insert into Users (
userId,
userName,
password,
corpName,
corpAddr,
corpTel,
corpFax,
userMail
) values (
'user01',
'user01',
'pass01',
'Comp001',
'Otani-ward, Tokyo',
'03-0000-0001',
'03-0000-0010',
'u1@corp1.co.jp'
);
insert into Users (
userId,
userName,
password,
corpName,
corpAddr,
corpTel,
corpFax,
userMail
) values (
'user02',
'user02',
'pass02',
'Comp02',
'Otani-ward, Tokyo',
'03-0000-0002',
'03-0000-0020',
'u2@corp2.co.jp'
);
create table Facilities (
faciCode char(10),
faciName char(100),
location char(100),
capacity integer,
layout char(100),
price integer,
primary key(faciCode)
);
insert into Facilities (
faciCode,
faciName,
location,
capacity,
layout,
price
) values (
'01',
'room01',
'Hechigo Hall 1st Building 1F',
20,
'Meeting Room',
50000
);
insert into Facilities (
faciCode,
faciName,
location,
capacity,
layout,
price
) values (
'02',
'room02',
'Hechigo Hall 1st Building 1F',
20,
'Meeting Room',
50000
);
insert into Facilities (
faciCode,
faciName,
location,
capacity,
layout,
price
) values (
'03',
'room03',
'Hechigo Hall 1st Building 1F',
40,
'Lecture Room',
100000
);
insert into Facilities (
faciCode,
faciName,
location,
capacity,
layout,
price
) values (
'04',
'hall01',
'Hechigo Hall 2nd Building 1F',
100,
'Event Hall',
250000
);
insert into Facilities (
faciCode,
faciName,
location,
capacity,
layout, price
) values (
'05',
'hall02',
'Hechigo Hall 2nd Building 2F',
200,
'Event Hall',
500000
);
create table Reserves (
reserveNo integer,
userId char(20),
faciCode char(10),
useYear integer,
useMonth integer,
useDay integer,
purpose char(100),
charge integer,
paymentFlg char(5) default 'false',
cancelFlg char(5) default 'false',
primary key(reserveNo),
foreign key(userId) references Users(userId),
foreign key(faciCode) references Facilities(faciCode)
);
insert into Reserves (
reserveNo,
userId,
faciCode,
useYear,
useMonth,
useDay,
purpose,
charge
) values (
1,
'user002',
'01',
2008,
6,
18,
'Meeting',
50000
);
insert into Reserves (
reserveNo,
userId,
faciCode,
useYear,
useMonth,
useDay,
purpose,
charge
) values (
2,
'user002',
'02',
2008,
6,
25,
'Meeting',
50000
);
insert into Reserves (
reserveNo,
userId,
faciCode,
useYear,
useMonth,
useDay,
purpose,
charge
) values (
3,
'user002',
'03',
2008,
7,
2,
'Lecture',
100000
);