01.酒店管理系统

/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     2017/1/2 16:06:52                            */
/*==============================================================*/


if exists (select 1
   from sys.sysreferences r join sys.sysobjects o on (o.id = r.constid and o.type = 'F')
   where r.fkeyid = object_id('GuestRecord') and o.name = 'FK_GUESTREC_REFERENCE_ROOM')
alter table GuestRecord
   drop constraint FK_GUESTREC_REFERENCE_ROOM
go

if exists (select 1
   from 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_ROOMSTAT')
alter table Room
   drop constraint FK_ROOM_REFERENCE_ROOMSTAT
go

if exists (select 1
   from 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_ROOMTYPE')
alter table Room
   drop constraint FK_ROOM_REFERENCE_ROOMTYPE
go

if exists (select 1
            from  sysobjects
           where  id = object_id('GuestRecord')
            and   type = 'U')
   drop table GuestRecord
go

if exists (select 1
            from  sysobjects
           where  id = object_id('Room')
            and   type = 'U')
   drop table Room
go

if exists (select 1
            from  sysobjects
           where  id = object_id('RoomState')
            and   type = 'U')
   drop table RoomState
go

if exists (select 1
            from  sysobjects
           where  id = object_id('RoomType')
            and   type = 'U')
   drop table RoomType
go

/*==============================================================*/
/* Table: GuestRecord                                           */
/*==============================================================*/
create table GuestRecord (
   GuestID              int                  not null,
   RoomID               int                  null,
   GuestName            nvarchar(32)         not null,
   IdentityID           varchar(36)          null,
   ResideDate           datetime             null,
   LeaveDate            datetime             null,
   Deposit              money                null,
   TotaMoney            money                null,
   constraint PK_GUESTRECORD primary key (GuestID)
)
go

/*==============================================================*/
/* Table: Room                                                  */
/*==============================================================*/
create table Room (
   RoomID               int                  not null,
   RoomStateID          int                  null,
   TypeID               int                  null,
   Description          varchar(100)         null,
   GuestNum             int                  null,
   RoomState            varchar(2)           null,
   RoomType             varchar(4)           null,
   constraint PK_ROOM primary key (RoomID)
)
go

/*==============================================================*/
/* Table: RoomState                                             */
/*==============================================================*/
create table RoomState (
   RoomStateID          int                  not null,
   RoomStateName        varchar(32)          not null,
   constraint PK_ROOMSTATE primary key (RoomStateID)
)
go

/*==============================================================*/
/* Table: RoomType                                              */
/*==============================================================*/
create table RoomType (
   TypeID               int                  not null,
   TypeName             varchar(32)          not null,
   BedNum               int                  not null,
   Price                money                not null,
   constraint PK_ROOMTYPE primary key (TypeID)
)
go

alter table GuestRecord
   add constraint FK_GUESTREC_REFERENCE_ROOM foreign key (RoomID)
      references Room (RoomID)
go

alter table Room
   add constraint FK_ROOM_REFERENCE_ROOMSTAT foreign key (RoomStateID)
      references RoomState (RoomStateID)
go

alter table Room
   add constraint FK_ROOM_REFERENCE_ROOMTYPE foreign key (TypeID)
      references RoomType (TypeID)
go


你可能感兴趣的:(优化MySchool)