创建数据库练习2

/*==============================================================*/
/* DBMS name:      Microsoft SQL Server 2005                    */
/* Created on:     2017/1/2 14:59:15                            */
/*==============================================================*/


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('CuestRecord') and o.name = 'FK_CUESTREC_REFERENCE_ROOM')
alter table CuestRecord
   drop constraint FK_CUESTREC_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('CuestRecord')
            and   type = 'U')
   drop table CuestRecord
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: CuestRecord                                           */
/*==============================================================*/
create table CuestRecord (
   CuestID              int                  not null,
   RoomID               int                  null,
   CuestName            numeric(0)           null,
   ResideDate           nvarchar(0)          null,
   LeaveDate            nvarchar(Max)        null,
   Deposit              float                null,
   TotaMoney            float                null,
   constraint PK_CUESTRECORD primary key (CuestID)
)
go

/*==============================================================*/
/* Table: Room                                                  */
/*==============================================================*/
create table Room (
   CuestID              int                  not null,
   RoomStateID          int                  null,
   TypeID               int                  null,
   RoomID               int                  null,
   Description          nvarchar(Max)        null,
   BedNum               int                  null,
   CuestNum             int                  null,
   RoomState            varchar(Max)         null,
   RoomType             nvarchar(0)          null,
   Price                int                  null,
   constraint PK_ROOM primary key (CuestID)
)
go

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

/*==============================================================*/
/* Table: RoomType                                              */
/*==============================================================*/
create table RoomType (
   TypeID               int                  not null,
   TypeName             nvarchar(0)          null,
   TypePrice            nvarchar(0)          null,
   BedNum               int                  null,
   constraint PK_ROOMTYPE primary key (TypeID)
)
go

alter table CuestRecord
   add constraint FK_CUESTREC_REFERENCE_ROOM foreign key (CuestID)
      references Room (CuestID)
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


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值