CREATE TABLE alias_entries (
	alias_entry_id int NOT NULL ,
	alias_id int NOT NULL ,
	user_id int NOT NULL ,
	user_alias varchar (64) NOT NULL ,
	CONSTRAINT PK_alias_entries PRIMARY KEY
	(
		alias_entry_id
	),
	CONSTRAINT UQ_alias_entries_1 UNIQUE
	(
		alias_id,
		user_id
	),
	CONSTRAINT UQ_alias_entries_2 UNIQUE
	(
		alias_id,
		user_alias
	),
	CONSTRAINT FK_alias_entries_to_aliases FOREIGN KEY
	(
		alias_id
	) REFERENCES aliases (
		alias_id
	),
	CONSTRAINT FK_alias_entries_to_users FOREIGN KEY
	(
		user_id
	) REFERENCES users (
		user_id
	),
	CONSTRAINT FK_alias_entries_to_objects FOREIGN KEY
	(
		alias_entry_id
	) REFERENCES objects (
		id
	)
)
GO


INSERT INTO classes (type, db_name, table_name, java_class)
	VALUES(9,	'building2', 'alias_entries', 'org.bodington.server.realm.AliasEntry')
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(9, 1, 'alias_entry_id', 'setAliasEntryId', 'getAliasEntryId', '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(9, 2, 'alias_id', 'setAliasId', 'getAliasId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 2, 8, 'setAlias', 'getAlias' )
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(9, 3, 'user_id', 'setUserId', 'getUserId', 'org.bodington.database.PrimaryKey', 'org.bodington.database.PrimaryKey', 2, 1, 'setUser', 'getUser' )
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(9, 4, 'user_alias', 'setUserAlias', 'getUserAlias', 'java.lang.String', 'java.lang.String', 0, null, null, null )
GO


