/****** Object:  Database FERIENCLUB_SQL    Script Date: 10.02.2006 21:59:07 ******/
IF EXISTS (SELECT name FROM master.dbo.sysdatabases WHERE name = N'FERIENCLUB_SQL')
	DROP DATABASE [FERIENCLUB_SQL]
GO

CREATE DATABASE [FERIENCLUB_SQL]  ON (NAME = N'FERIENCLUB_SQL_Data', FILENAME = N'd:\programme\entwicklung\datenbanken\SQL-Server\MSSQL$FERIENCLUB_SQL\data\FERIENCLUB_SQL_Data.MDF' , SIZE = 2, FILEGROWTH = 10%) LOG ON (NAME = N'FERIENCLUB_SQL_Log', FILENAME = N'd:\programme\entwicklung\datenbanken\SQL-Server\MSSQL$FERIENCLUB_SQL\data\FERIENCLUB_SQL_Log.LDF' , SIZE = 1, FILEGROWTH = 10%)
 COLLATE SQL_Latin1_General_CP1_CI_AS
GO

exec sp_dboption N'FERIENCLUB_SQL', N'autoclose', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'bulkcopy', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'trunc. log', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'torn page detection', N'true'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'read only', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'dbo use', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'single', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'autoshrink', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'ANSI null default', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'recursive triggers', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'ANSI nulls', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'concat null yields null', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'cursor close on commit', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'default to local cursor', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'quoted identifier', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'ANSI warnings', N'false'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'auto create statistics', N'true'
GO

exec sp_dboption N'FERIENCLUB_SQL', N'auto update statistics', N'true'
GO

use [FERIENCLUB_SQL]
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_USER_PTT_ADDRESS]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_USER] DROP CONSTRAINT FK_PTT_USER_PTT_ADDRESS
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_APPOINTMENT_USER_PTT_APPOINTMENT]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_APPOINTMENT_USER] DROP CONSTRAINT FK_PTT_APPOINTMENT_USER_PTT_APPOINTMENT
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_HISTORY_PTT_HISTORYENTRY_TYPE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_HISTORY] DROP CONSTRAINT FK_PTT_HISTORY_PTT_HISTORYENTRY_TYPE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_APPOINTMENT_PTT_PLACE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_APPOINTMENT] DROP CONSTRAINT FK_PTT_APPOINTMENT_PTT_PLACE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_APPOINTMENT_PTT_PLACE1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_APPOINTMENT] DROP CONSTRAINT FK_PTT_APPOINTMENT_PTT_PLACE1
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_APPOINTMENT_USER_PTT_USER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_APPOINTMENT_USER] DROP CONSTRAINT FK_PTT_APPOINTMENT_USER_PTT_USER
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_HISTORY_PTT_USER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_HISTORY] DROP CONSTRAINT FK_PTT_HISTORY_PTT_USER
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_PTT_USER_PREFERENCES_PTT_USER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[PTT_USER_PREFERENCES] DROP CONSTRAINT FK_PTT_USER_PREFERENCES_PTT_USER
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_BOOKING_USER_VM_BOOKING]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_BOOKING_USER] DROP CONSTRAINT FK_VM_BOOKING_USER_VM_BOOKING
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_ROOM_BOOKING_VM_BOOKING]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_ROOM_BOOKING] DROP CONSTRAINT FK_VM_ROOM_BOOKING_VM_BOOKING
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_ROOM_BOOKING_VM_ROOM]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_ROOM_BOOKING] DROP CONSTRAINT FK_VM_ROOM_BOOKING_VM_ROOM
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_ROOM_VM_ROOMTYPE]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_ROOM] DROP CONSTRAINT FK_VM_ROOM_VM_ROOMTYPE
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_BOOKING_VM_USER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_BOOKING] DROP CONSTRAINT FK_VM_BOOKING_VM_USER
GO

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_VM_BOOKING_USER_VM_USER]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[VM_BOOKING_USER] DROP CONSTRAINT FK_VM_BOOKING_USER_VM_USER
GO

/****** Object:  Table [dbo].[PTT_ADDRESS]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_ADDRESS]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_ADDRESS]
GO

/****** Object:  Table [dbo].[PTT_APPOINTMENT]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_APPOINTMENT]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_APPOINTMENT]
GO

/****** Object:  Table [dbo].[PTT_APPOINTMENT_USER]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_APPOINTMENT_USER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_APPOINTMENT_USER]
GO

/****** Object:  Table [dbo].[PTT_HISTORY]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_HISTORY]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_HISTORY]
GO

/****** Object:  Table [dbo].[PTT_HISTORYENTRY_TYPE]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_HISTORYENTRY_TYPE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_HISTORYENTRY_TYPE]
GO

/****** Object:  Table [dbo].[PTT_PLACE]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_PLACE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_PLACE]
GO

/****** Object:  Table [dbo].[PTT_USER]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_USER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_USER]
GO

/****** Object:  Table [dbo].[PTT_USER_PREFERENCES]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[PTT_USER_PREFERENCES]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[PTT_USER_PREFERENCES]
GO

/****** Object:  Table [dbo].[VM_BOOKING]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_BOOKING]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_BOOKING]
GO

/****** Object:  Table [dbo].[VM_BOOKING_USER]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_BOOKING_USER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_BOOKING_USER]
GO

/****** Object:  Table [dbo].[VM_ROOM]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_ROOM]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_ROOM]
GO

/****** Object:  Table [dbo].[VM_ROOMTYPE]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_ROOMTYPE]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_ROOMTYPE]
GO

/****** Object:  Table [dbo].[VM_ROOM_BOOKING]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_ROOM_BOOKING]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_ROOM_BOOKING]
GO

/****** Object:  Table [dbo].[VM_USER]    Script Date: 10.02.2006 21:59:07 ******/
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[VM_USER]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[VM_USER]
GO

/****** Object:  Table [dbo].[PTT_ADDRESS]    Script Date: 10.02.2006 21:59:10 ******/
CREATE TABLE [dbo].[PTT_ADDRESS] (
	[ADDRESSID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[COUNTRY] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[PROVINCE] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ZIPCODE] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[STREET] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[EMAIL] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[PHONE] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_APPOINTMENT]    Script Date: 10.02.2006 21:59:11 ******/
CREATE TABLE [dbo].[PTT_APPOINTMENT] (
	[APPOINTMENTID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[SUBJECT] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[DATETIME] [datetime] NULL ,
	[DURATION] [int] NULL ,
	[CATEGORY] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[PLACEID] [uniqueidentifier] NULL ,
	[STATUS] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_APPOINTMENT_USER]    Script Date: 10.02.2006 21:59:11 ******/
CREATE TABLE [dbo].[PTT_APPOINTMENT_USER] (
	[USERID] [uniqueidentifier] NOT NULL ,
	[APPOINTMENTID] [uniqueidentifier] NOT NULL ,
	[LEAD] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[STATUS] [char] (1) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_HISTORY]    Script Date: 10.02.2006 21:59:11 ******/
CREATE TABLE [dbo].[PTT_HISTORY] (
	[ENTRYID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[USERID] [uniqueidentifier] NULL ,
	[ENTRYTYPEID] [uniqueidentifier] NULL ,
	[ENTRYTEXT] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ENTRYDATE] [datetime] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_HISTORYENTRY_TYPE]    Script Date: 10.02.2006 21:59:11 ******/
CREATE TABLE [dbo].[PTT_HISTORYENTRY_TYPE] (
	[ENTRYTYPEID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[ENTRYTYPEDESC] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_PLACE]    Script Date: 10.02.2006 21:59:11 ******/
CREATE TABLE [dbo].[PTT_PLACE] (
	[PLACEID] [uniqueidentifier] NOT NULL ,
	[NAME] [varchar] (100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[LONGITUDE] [float] NULL ,
	[LATITUDE] [float] NULL ,
	[VALIDRANGE] [float] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_USER]    Script Date: 10.02.2006 21:59:12 ******/
CREATE TABLE [dbo].[PTT_USER] (
	[USERID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[SALUTATION] [varchar] (10) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[BIRTHDATE] [datetime] NULL ,
	[NAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[FIRSTNAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[PASSWORD] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ADDRESSID] [uniqueidentifier] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[PTT_USER_PREFERENCES]    Script Date: 10.02.2006 21:59:12 ******/
CREATE TABLE [dbo].[PTT_USER_PREFERENCES] (
	[USERID] [uniqueidentifier] NOT NULL ,
	[PREFERENCENAME] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
	[PREFERENCEVALUE] [int] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_BOOKING]    Script Date: 10.02.2006 21:59:12 ******/
CREATE TABLE [dbo].[VM_BOOKING] (
	[BOOKINGID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[BOOKINGUSER] [uniqueidentifier] NULL ,
	[FROMDATE] [datetime] NULL ,
	[TODATE] [datetime] NULL ,
	[STATUS] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_BOOKING_USER]    Script Date: 10.02.2006 21:59:12 ******/
CREATE TABLE [dbo].[VM_BOOKING_USER] (
	[BOOKINGID] [uniqueidentifier] NOT NULL ,
	[USERID] [uniqueidentifier] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_ROOM]    Script Date: 10.02.2006 21:59:13 ******/
CREATE TABLE [dbo].[VM_ROOM] (
	[ROOMID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[ROOMNO] [int] NULL ,
	[STATUS] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[TYPE] [uniqueidentifier] NULL ,
	[FLOOR] [int] NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_ROOMTYPE]    Script Date: 10.02.2006 21:59:13 ******/
CREATE TABLE [dbo].[VM_ROOMTYPE] (
	[ROOMTYPEID]  uniqueidentifier ROWGUIDCOL  NOT NULL ,
	[ROOMCATEGORY] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
	[ROOMTYPEDESC] [varchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_ROOM_BOOKING]    Script Date: 10.02.2006 21:59:13 ******/
CREATE TABLE [dbo].[VM_ROOM_BOOKING] (
	[BOOKINGID] [uniqueidentifier] NOT NULL ,
	[ROOMID] [uniqueidentifier] NOT NULL 
) ON [PRIMARY]
GO

/****** Object:  Table [dbo].[VM_USER]    Script Date: 10.02.2006 21:59:13 ******/
CREATE TABLE [dbo].[VM_USER] (
	[USERID]  uniqueidentifier ROWGUIDCOL  NOT NULL 
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[PTT_ADDRESS] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_ADDRESS] PRIMARY KEY  CLUSTERED 
	(
		[ADDRESSID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_APPOINTMENT] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_APPOINTMENT] PRIMARY KEY  CLUSTERED 
	(
		[APPOINTMENTID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_APPOINTMENT_USER] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_APPOINTMENT_USER] PRIMARY KEY  CLUSTERED 
	(
		[USERID],
		[APPOINTMENTID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_HISTORY] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_HISTORY] PRIMARY KEY  CLUSTERED 
	(
		[ENTRYID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_HISTORYENTRY_TYPE] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_HISTORYENTRY_TYPE] PRIMARY KEY  CLUSTERED 
	(
		[ENTRYTYPEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_PLACE] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_PLACE] PRIMARY KEY  CLUSTERED 
	(
		[PLACEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_USER] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_USER] PRIMARY KEY  CLUSTERED 
	(
		[USERID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_USER_PREFERENCES] WITH NOCHECK ADD 
	CONSTRAINT [PK_PTT_USER_PREFERENCES] PRIMARY KEY  CLUSTERED 
	(
		[USERID],
		[PREFERENCENAME]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_BOOKING] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_BOOKING] PRIMARY KEY  CLUSTERED 
	(
		[BOOKINGID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_BOOKING_USER] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_BOOKING_USER] PRIMARY KEY  CLUSTERED 
	(
		[BOOKINGID],
		[USERID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_ROOM] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_ROOM] PRIMARY KEY  CLUSTERED 
	(
		[ROOMID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_ROOMTYPE] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_ROOMTYPE] PRIMARY KEY  CLUSTERED 
	(
		[ROOMTYPEID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_ROOM_BOOKING] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_ROOM_BOOKING] PRIMARY KEY  CLUSTERED 
	(
		[BOOKINGID],
		[ROOMID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[VM_USER] WITH NOCHECK ADD 
	CONSTRAINT [PK_VM_USER] PRIMARY KEY  CLUSTERED 
	(
		[USERID]
	)  ON [PRIMARY] 
GO

ALTER TABLE [dbo].[PTT_ADDRESS] WITH NOCHECK ADD 
	CONSTRAINT [DF_PTT_ADDRESS_ADDRESSID] DEFAULT (newid()) FOR [ADDRESSID]
GO

ALTER TABLE [dbo].[PTT_APPOINTMENT] WITH NOCHECK ADD 
	CONSTRAINT [DF_PTT_APPOINTMENT_APPOINTMENTID] DEFAULT (newid()) FOR [APPOINTMENTID]
GO

ALTER TABLE [dbo].[PTT_HISTORY] WITH NOCHECK ADD 
	CONSTRAINT [DF_PTT_HISTORY_ENTRYID] DEFAULT (newid()) FOR [ENTRYID]
GO

ALTER TABLE [dbo].[PTT_HISTORYENTRY_TYPE] WITH NOCHECK ADD 
	CONSTRAINT [DF_PTT_HISTORYENTRY_TYPE_ENTRYTYPEID] DEFAULT (newid()) FOR [ENTRYTYPEID]
GO

ALTER TABLE [dbo].[PTT_USER] WITH NOCHECK ADD 
	CONSTRAINT [DF_PTT_USER_USERID] DEFAULT (newid()) FOR [USERID]
GO

ALTER TABLE [dbo].[VM_BOOKING] WITH NOCHECK ADD 
	CONSTRAINT [DF_VM_BOOKING_BOOKINGID] DEFAULT (newid()) FOR [BOOKINGID]
GO

ALTER TABLE [dbo].[VM_ROOM] WITH NOCHECK ADD 
	CONSTRAINT [DF_VM_ROOM_ROOMID] DEFAULT (newid()) FOR [ROOMID]
GO

ALTER TABLE [dbo].[VM_ROOMTYPE] WITH NOCHECK ADD 
	CONSTRAINT [DF_VM_ROOMTYPE_ROOMTYPEID] DEFAULT (newid()) FOR [ROOMTYPEID]
GO

ALTER TABLE [dbo].[VM_USER] WITH NOCHECK ADD 
	CONSTRAINT [DF_VM_USER_USERID] DEFAULT (newid()) FOR [USERID]
GO

ALTER TABLE [dbo].[PTT_APPOINTMENT] ADD 
	CONSTRAINT [FK_PTT_APPOINTMENT_PTT_PLACE] FOREIGN KEY 
	(
		[PLACEID]
	) REFERENCES [dbo].[PTT_PLACE] (
		[PLACEID]
	),
	CONSTRAINT [FK_PTT_APPOINTMENT_PTT_PLACE1] FOREIGN KEY 
	(
		[PLACEID]
	) REFERENCES [dbo].[PTT_PLACE] (
		[PLACEID]
	)
GO

ALTER TABLE [dbo].[PTT_APPOINTMENT_USER] ADD 
	CONSTRAINT [FK_PTT_APPOINTMENT_USER_PTT_APPOINTMENT] FOREIGN KEY 
	(
		[APPOINTMENTID]
	) REFERENCES [dbo].[PTT_APPOINTMENT] (
		[APPOINTMENTID]
	),
	CONSTRAINT [FK_PTT_APPOINTMENT_USER_PTT_USER] FOREIGN KEY 
	(
		[USERID]
	) REFERENCES [dbo].[PTT_USER] (
		[USERID]
	)
GO

ALTER TABLE [dbo].[PTT_HISTORY] ADD 
	CONSTRAINT [FK_PTT_HISTORY_PTT_HISTORYENTRY_TYPE] FOREIGN KEY 
	(
		[ENTRYTYPEID]
	) REFERENCES [dbo].[PTT_HISTORYENTRY_TYPE] (
		[ENTRYTYPEID]
	),
	CONSTRAINT [FK_PTT_HISTORY_PTT_USER] FOREIGN KEY 
	(
		[USERID]
	) REFERENCES [dbo].[PTT_USER] (
		[USERID]
	)
GO

ALTER TABLE [dbo].[PTT_USER] ADD 
	CONSTRAINT [FK_PTT_USER_PTT_ADDRESS] FOREIGN KEY 
	(
		[ADDRESSID]
	) REFERENCES [dbo].[PTT_ADDRESS] (
		[ADDRESSID]
	)
GO

ALTER TABLE [dbo].[PTT_USER_PREFERENCES] ADD 
	CONSTRAINT [FK_PTT_USER_PREFERENCES_PTT_USER] FOREIGN KEY 
	(
		[USERID]
	) REFERENCES [dbo].[PTT_USER] (
		[USERID]
	)
GO

ALTER TABLE [dbo].[VM_BOOKING] ADD 
	CONSTRAINT [FK_VM_BOOKING_VM_USER] FOREIGN KEY 
	(
		[BOOKINGUSER]
	) REFERENCES [dbo].[VM_USER] (
		[USERID]
	)
GO

ALTER TABLE [dbo].[VM_BOOKING_USER] ADD 
	CONSTRAINT [FK_VM_BOOKING_USER_VM_BOOKING] FOREIGN KEY 
	(
		[BOOKINGID]
	) REFERENCES [dbo].[VM_BOOKING] (
		[BOOKINGID]
	),
	CONSTRAINT [FK_VM_BOOKING_USER_VM_USER] FOREIGN KEY 
	(
		[USERID]
	) REFERENCES [dbo].[VM_USER] (
		[USERID]
	)
GO

ALTER TABLE [dbo].[VM_ROOM] ADD 
	CONSTRAINT [FK_VM_ROOM_VM_ROOMTYPE] FOREIGN KEY 
	(
		[TYPE]
	) REFERENCES [dbo].[VM_ROOMTYPE] (
		[ROOMTYPEID]
	)
GO

ALTER TABLE [dbo].[VM_ROOM_BOOKING] ADD 
	CONSTRAINT [FK_VM_ROOM_BOOKING_VM_BOOKING] FOREIGN KEY 
	(
		[BOOKINGID]
	) REFERENCES [dbo].[VM_BOOKING] (
		[BOOKINGID]
	),
	CONSTRAINT [FK_VM_ROOM_BOOKING_VM_ROOM] FOREIGN KEY 
	(
		[ROOMID]
	) REFERENCES [dbo].[VM_ROOM] (
		[ROOMID]
	)
GO

