CREATE TABLE members (
	member_id int NOT NULL ,
	group_id int NOT NULL ,
	user_id int NOT NULL ,
	CONSTRAINT PK_members PRIMARY KEY
	(
		member_id
	),
	CONSTRAINT UQ_members_group_user UNIQUE   
	(
		group_id,
		user_id
	),
	CONSTRAINT FK_members_to_objects FOREIGN KEY
	(
		member_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_members_to_groups FOREIGN KEY
	(
		group_id
	) REFERENCES groups (
		group_id
	),
	CONSTRAINT FK_members_to_users FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	)
)
GO


INSERT INTO classes (type, db_name, table_name, java_class)
	VALUES(4,	'building2', 'members', 'org.bodington.server.realm.Member')
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(4, 1, 'member_id', 'setMemberId', 'getMemberId', '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(4, 2, 'group_id', 'setGroupId', 'getGroupId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 2, 3, 'setGroup', 'getGroup' )
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(4, 3, 'user_id', 'setUserId', 'getUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 2, 1, 'setUser', 'getUser' )
GO



