CREATE TABLE resource_event_users (
	resource_event_user_id int NOT NULL ,
	resource_id int,
	user_id int,
	CONSTRAINT PK_resource_event_users PRIMARY KEY
	(
		resource_event_user_id
	),
	CONSTRAINT UQ_resource_event_users_1 UNIQUE
	(
		resource_id,
		user_id
	),
	CONSTRAINT FK_rsrce_evnt_usrs_to_objects FOREIGN KEY
	(
		resource_event_user_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_rsrce_evnt_usrs_to_resrces FOREIGN KEY
	(
		resource_id
	) REFERENCES resources (
		resource_id
	),
	CONSTRAINT FK_rsrce_evnt_usrs_to_users FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	)
)
GO


INSERT INTO classes (type, db_name, table_name, java_class)
	VALUES(18,	'building2', 'resource_event_users', 'org.bodington.server.events.ResourceEventUser')
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(18, 1, 'resource_event_user_id', 'setResourceEventUserId', 'getResourceEventUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 1, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(18, 2, 'resource_id', 'setResourceId', 'getResourceId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

INSERT INTO fields (type, sequence, field, set_method_name, get_method_name, set_java_class, get_java_class, flags, foreign_type, set_method_name_foreign, get_method_name_foreign )
	VALUES(18, 3, 'user_id', 'setUserId', 'getUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 0, null, null, null )
GO

