IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'[dbo].[CleanStatusLog]') AND OBJECTPROPERTY(id, N'IsUserTable') = 1)
BEGIN
CREATE TABLE [dbo].[CleanStatusLog](
	[Id] [int] IDENTITY(1,1) NOT NULL,
	[DateStamp] [datetime] NOT NULL,
	[FK_UserIdNumber] [int] NOT NULL,
	[FK_RoomNumber] [int] NOT NULL,
	[CleanStatus] [int] NOT NULL,
 CONSTRAINT [PK_CleanStatusLogIDPK] PRIMARY KEY CLUSTERED 
(
	[Id] ASC
)
) ON [PRIMARY]
END
GO

IF NOT EXISTS (SELECT * FROM INFORMATION_SCHEMA.REFERENTIAL_CONSTRAINTS WHERE CONSTRAINT_NAME='FK_CleanStatusLog_Personel')
BEGIN
  ALTER TABLE [dbo].[CleanStatusLog]  WITH CHECK ADD  CONSTRAINT [FK_CleanStatusLog_Personel] FOREIGN KEY([FK_UserIdNumber])
  REFERENCES [dbo].[Personel] ([UserIDNumber])

  ALTER TABLE [dbo].[CleanStatusLog] CHECK CONSTRAINT [FK_CleanStatusLog_Personel]

  ALTER TABLE [dbo].[CleanStatusLog]  WITH CHECK ADD  CONSTRAINT [FK_CleanStatusLog_Rooms] FOREIGN KEY([FK_RoomNumber])
  REFERENCES [dbo].[Rooms] ([RoomNumber])

  ALTER TABLE [dbo].[CleanStatusLog] CHECK CONSTRAINT [FK_CleanStatusLog_Rooms]
END