/*==============================================================*//* DBMS name: Microsoft SQL Server 2008 *//* Created on: 2018/4/29 9:23:18 *//*==============================================================*/
if exists (select1from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('Customer') and o.name = 'FK_CUSTOMER_REFERENCE_HOTEL')
altertable Customer
dropconstraint FK_CUSTOMER_REFERENCE_HOTEL
goifexists (select1from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('creditCard') and o.name = 'FK_CREDITCA_REFERENCE_CUSTOMER')
altertable creditCard
dropconstraint FK_CREDITCA_REFERENCE_CUSTOMER
goifexists (select1from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('room') and o.name = 'FK_ROOM_REFERENCE_HOTEL')
altertable room
dropconstraint FK_ROOM_REFERENCE_HOTEL
goifexists (select1from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
where r.fkeyid = object_id('room') and o.name = 'FK_ROOM_REFERENCE_CUSTOMER')
altertable room
dropconstraint FK_ROOM_REFERENCE_CUSTOMER
goifexists (select1from sysobjects
where id = object_id('Customer')
and type = 'U')
droptable Customer
goifexists (select1from sysobjects
where id = object_id('creditCard')
and type = 'U')
droptable creditCard
goifexists (select1from sysobjects
where id = object_id('hotel')
and type = 'U')
droptable hotel
goifexists (select1from sysobjects
where id = object_id('room')
and type = 'U')
droptable room
go
/*==============================================================*/
/* Table: Customer */
/*==============================================================*/
createtable Customer (
account text notnull,
fullName text null,
emailAddress text notnull,
hotelID intnull,
constraint PK_CUSTOMER primarykey (account)
)
go
/*==============================================================*/
/* Table: creditCard */
/*==============================================================*/
createtable creditCard (
cardID intnotnull,
account text notnull,
password text notnull,
constraint PK_CREDITCARD primarykey (cardID)
)
go
/*==============================================================*/
/* Table: hotel */
/*==============================================================*/
createtable hotel (
hotelID intnotnull,
name text notnull,
locationID intnotnull,
star intnotnull,
constraint PK_HOTEL primarykey (hotelID)
)
go
/*==============================================================*/
/* Table: room */
/*==============================================================*/
createtable room (
roomID intnotnull,
hotelID intnotnull,
account text null,
type text null,
price floatnotnull,
isAvailable bitnotnull,
constraint PK_ROOM primarykey (roomID)
)
goaltertable Customer
addconstraint FK_CUSTOMER_REFERENCE_HOTEL foreignkey (hotelID)
references hotel (hotelID)
goaltertable creditCard
addconstraint FK_CREDITCA_REFERENCE_CUSTOMER foreignkey (account)
references Customer (account)
goaltertable room
addconstraint FK_ROOM_REFERENCE_HOTEL foreignkey (hotelID)
references hotel (hotelID)
goaltertable room
addconstraint FK_ROOM_REFERENCE_CUSTOMER foreignkey (account)
references Customer (account)
go