/*==============================================================*/
/* DBMS name: Sybase SQL Anywhere 12 */
/* Created on: 2018/4/29 16:18:13 */
/*==============================================================*/
if exists(select 1 from sys.sysforeignkey where role='FK_旅客_REFERENCE_银行卡') then
alter table 旅客
delete foreign key FK_旅客_REFERENCE_银行卡
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_旅客_REFERENCE_购物车') then
alter table 旅客
delete foreign key FK_旅客_REFERENCE_购物车
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_订单_REFERENCE_房间') then
alter table 订单
delete foreign key FK_订单_REFERENCE_房间
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_购物车_REFERENCE_订单') then
alter table 购物车
delete foreign key FK_购物车_REFERENCE_订单
end if;
if exists(select 1 from sys.sysforeignkey where role='FK_酒店_REFERENCE_房间') then
alter table 酒店
delete foreign key FK_酒店_REFERENCE_房间
end if;
drop table if exists 房间;
drop table if exists 旅客;
drop table if exists 订单;
drop table if exists 购物车;
drop table if exists 酒店;
drop table if exists 银行卡;
/*==============================================================*/
/* Table: 房间 */
/*==============================================================*/
create table 房间
(
房间id integer not null,
订单id integer null,
酒店id integer null,
大小 smallint null,
类型 varchar null,
开始时间 timestamp null,
结束时间 timestamp null,
constraint PK_房间 primary key clustered (房间id)
);
/*==============================================================*/
/* Table: 旅客 */
/*==============================================================*/
create table 旅客
(
id integer not null,
订单id varchar(8) null,
name long varchar null,
email long varchar null,
constraint PK_旅客 primary key clustered (id)
);
/*==============================================================*/
/* Table: 订单 */
/*==============================================================*/
create table 订单
(
id varchar(8) not null,
房间id integer null,
price integer null,
constraint PK_订单 primary key clustered (id)
);
/*==============================================================*/
/* Table: 购物车 */
/*==============================================================*/
create table 购物车
(
订单id varchar(8) not null,
id varchar(8) null,
客户id varchar(6) null,
总价格 integer null,
总订单数量 integer null,
constraint PK_购物车 primary key clustered (订单id)
);
/*==============================================================*/
/* Table: 酒店 */
/*==============================================================*/
create table 酒店
(
酒店id integer not null,
房间id integer null,
房间数量 integer null,
位置 long varchar null,
级别 smallint null,
constraint PK_酒店 primary key clustered (酒店id)
);
/*==============================================================*/
/* Table: 银行卡 */
/*==============================================================*/
create table 银行卡
(
id integer not null,
passwd varchar(6) not null,
type char(10) null,
constraint PK_银行卡 primary key clustered (id)
);
alter table 旅客
add constraint FK_旅客_REFERENCE_银行卡 foreign key (id)
references 银行卡 (id)
on update restrict
on delete restrict;
alter table 旅客
add constraint FK_旅客_REFERENCE_购物车 foreign key (订单id)
references 购物车 (订单id)
on update restrict
on delete restrict;
alter table 订单
add constraint FK_订单_REFERENCE_房间 foreign key (房间id)
references 房间 (房间id)
on update restrict
on delete restrict;
alter table 购物车
add constraint FK_购物车_REFERENCE_订单 foreign key (id)
references 订单 (id)
on update restrict
on delete restrict;
alter table 酒店
add constraint FK_酒店_REFERENCE_房间 foreign key (房间id)
references 房间 (房间id)
on update restrict
on delete restrict;