/* Table contains data fields, a primary key constraint and a foreign key constraints       */
/* The constraints are designed to limit damage to data integrity in the event of           */ 
/* programmer error or other unforeseen circumstances.                                      */

/* Log book questions are a type of object hence the foreign key reference to objects and    */
/* should only occur with reference to specific log book sections hence foreign key          */
/* reference to that table.  There are also references to the big_strings table              */

CREATE TABLE log_book_questions (
	log_book_question_id int NOT NULL ,
	log_book_section_id int NOT NULL ,
	title_big_string_id int NOT NULL ,
	question_big_string_id int NOT NULL ,
	help_big_string_id int NOT NULL ,
	ordinal int NOT NULL,
	CONSTRAINT PK_log_book_questions PRIMARY KEY
	(
		log_book_question_id
	),
	CONSTRAINT FK_log_book_q_to_objs FOREIGN KEY
	(
		log_book_question_id
	) REFERENCES objects (
		id
	),
	CONSTRAINT FK_log_book_q_to_secs FOREIGN KEY
	(
		log_book_section_id
	) REFERENCES log_book_sections (
		log_book_section_id
	),
	CONSTRAINT FK_log_book_q_t_to_bgstrs FOREIGN KEY
	(
		title_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_log_book_q_q_to_bgstrs FOREIGN KEY
	(
		question_big_string_id
	) REFERENCES big_strings (
		big_string_id
	),
	CONSTRAINT FK_log_book_q_h_to_bgstrs FOREIGN KEY
	(
		help_big_string_id
	) REFERENCES big_strings (
		big_string_id
	)
)
GO

/* The rest of this SQL is deployment information as described in LogBook.sql */


INSERT INTO classes (type, super_type, db_name, table_name, java_class)
	VALUES(51, null, null, 'log_book_questions', 'org.bodington.logbook.server.LogBookQuestion')
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(51, 1, 'log_book_question_id', 'setLogBookQuestionId', 'getLogBookQuestionId', '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(51, 2, 'log_book_section_id', 'setLogBookSectionId', 'getLogBookSectionId', '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(51, 3, 'title_big_string_id', 'setTitleBigStringId', 'getTitleBigStringId', '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(51, 4, 'question_big_string_id', 'setQuestionBigStringId', 'getQuestionBigStringId', '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(51, 5, 'help_big_string_id', 'setHelpBigStringId', 'getHelpBigStringId', '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(51, 6, 'ordinal', 'setOrdinal', 'getOrdinal', 'int', 'int', 0, null, null, null )
GO




