CREATE TABLE teacher_tbl (teacher_id bigint PRIMARY KEY AUTO_INCREMENT, teacher_nam character varying(50) NOT NULL, login_id character varying(20) UNIQUE NOT NULL,mail_ad character varying(100) DEFAULT '', passwd character varying(20) NOT NULL,tel_num character varying(50) DEFAULT '', addr character varying(100) DEFAULT '', belong character varying(100), comment text, status int NOT NULL DEFAULT 1);
INSERT INTO teacher_tbl VALUES (1, 'iitaka','toshibo666', 'mail', 'toshibo666', 'denwa', 'zyusyo', 'syozoku', 'bikou', 1);
CREATE TABLE department_tbl (department_id int PRIMARY KEY AUTO_INCREMENT, department_nam TEXT NOT NULL, comment TEXT);
CREATE TABLE grade_tbl (grade_id int PRIMARY KEY AUTO_INCREMENT, grade_nam TEXT NOT NULL, comment TEXT);
CREATE TABLE txt_level_tbl (txt_level_id int PRIMARY KEY AUTO_INCREMENT, txt_level_nam TEXT NOT NULL, comment TEXT);
CREATE TABLE difficulty_tbl (difficulty_id int PRIMARY KEY AUTO_INCREMENT, difficulty_nam TEXT NOT NULL, comment TEXT);
CREATE TABLE test_txt_tbl (text_id bigint PRIMARY KEY AUTO_INCREMENT, text_title text NOT NULL, exp_dif int DEFAULT NULL, real_dif int DEFAULT NULL, level int DEFAULT NULL, content text NOT NULL, teacher_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, registered_date timestamp DEFAULT now(), last_modifer_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, last_modified_date timestamp, department_id int DEFAULT NULL,comment text,av_file text,av_repeat int,img_file text);
CREATE INDEX test_txt_tbl_level_index ON test_txt_tbl (level);
CREATE TABLE question_tbl (question_id bigint PRIMARY KEY AUTO_INCREMENT, text_id bigint NOT NULL REFERENCES test_txt_tbl (text_id) ON DELETE CASCADE, exp_dif int DEFAULT NULL,real_dif int DEFAULT NULL, level int DEFAULT NULL,content text NOT NULL, teacher_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, registered_date timestamp DEFAULT now(), last_modifer_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, last_modified_date timestamp, comment text,answer int NOT NULL,example text DEFAULT NULL,rep_key character varying(20) DEFAULT '',max_length int DEFAULT NULL,max_words int DEFAULT NULL,question_av_file text, question_repeat int DEFAULT 1,ave_percent int DEFAULT 0, ave_sd float8);
CREATE TABLE item_tbl (question_id bigint NOT NULL REFERENCES question_tbl(question_id) ON DELETE CASCADE, item_order character varying(2) NOT NULL, item_txt text NOT NULL,is_right int NOT NULL,comment text, CONSTRAINT item_tbl_pk PRIMARY KEY(question_id, item_order));
CREATE INDEX item_tbl_question_id_index ON item_tbl (question_id);
CREATE TABLE template_tbl (template_id BIGINT PRIMARY KEY AUTO_INCREMENT, template_name TEXT,teacher_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, registered_date timestamp DEFAULT now(), last_modifer_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, last_modified_date timestamp,sd_score float8,ave_score float8,participate_num int, full_score int);
CREATE TABLE class_info_tbl (class_id bigint PRIMARY KEY AUTO_INCREMENT, class_nam character varying(50) NOT NULL DEFAULT '���L��', teacher_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL, grade int DEFAULT NULL,level int DEFAULT NULL,belong text,comment text,status int NOT NULL,registered_num int DEFAULT NULL,registered_date timestamp NOT NULL DEFAULT now() );
CREATE INDEX class_info_tbl_tea_id_index ON class_info_tbl (teacher_id);
CREATE INDEX class_info_tbl_grade_index ON class_info_tbl (grade);
CREATE INDEX class_info_tbl_level_index ON class_info_tbl (level);
CREATE TABLE student_tbl (student_id bigint PRIMARY KEY AUTO_INCREMENT, student_nam character varying(50) NOT NULL DEFAULT '���L��', login_id character varying(20) UNIQUE NOT NULL,mail_ad character varying(100) NOT NULL,passwd character varying(20) NOT NULL,tel_num character varying(20) DEFAULT '���L��',addr text,belong text,comment text,status int NOT NULL,grade int DEFAULT NULL,registered_date timestamp NOT NULL DEFAULT now());
CREATE INDEX student_tbl_tea_id_index ON student_tbl (grade);
CREATE TABLE test_info_tbl (test_id bigint PRIMARY KEY AUTO_INCREMENT, test_nam character varying(50) NOT NULL DEFAULT '���L��', teacher_id bigint REFERENCES teacher_tbl (teacher_id) ON DELETE SET NULL,class_id bigint REFERENCES class_info_tbl (class_id) ON DELETE CASCADE,make_date timestamp NOT NULL DEFAULT now(),test_date timestamp, duration int DEFAULT 0,exp_score float8 DEFAULT 0,real_score float8 DEFAULT 0,status int NOT NULL DEFAULT 0,partici_num int DEFAULT 0,sd_score float8 DEFAULT 0,test_type smallint DEFAULT 0,template_type bigint REFERENCES template_tbl (template_id) ON DELETE SET NULL, full_score int);
CREATE INDEX test_info_tbl_tea_id_index ON test_info_tbl (teacher_id);
CREATE INDEX test_info_tbl_class_id_index ON test_info_tbl (class_id);
CREATE TABLE tested_question_tbl (tested_id bigint PRIMARY KEY AUTO_INCREMENT, question_type bigint REFERENCES question_tbl (question_id) ON DELETE CASCADE,test_id bigint REFERENCES test_info_tbl (test_id) ON DELETE CASCADE,score int DEFAULT 0,question_order int DEFAULT 0,comment text,ave_score float8 DEFAULT 0,sddev float8 DEFAULT 0,CONSTRAINT tested_question_tbl_uni UNIQUE(question_type, test_id));
CREATE INDEX tested_que_tbl_question_id_index ON tested_question_tbl (question_type);
CREATE TABLE class_student_tbl (class_student_id int PRIMARY KEY AUTO_INCREMENT, student_id bigint REFERENCES student_tbl (student_id) ON DELETE CASCADE,class_id bigint REFERENCES class_info_tbl (class_id) ON DELETE CASCADE,student_comment text,teacher_comment text,present int DEFAULT 0,status int DEFAULT 0,CONSTRAINT class_student_tbl_uni UNIQUE(student_id, class_id));
CREATE INDEX class_st_tbl_class_id_index ON class_student_tbl (class_id);
CREATE TABLE key_word_tbl (key_word_id bigint PRIMARY KEY AUTO_INCREMENT, question_id bigint NOT NULL REFERENCES question_tbl(question_id) ON DELETE CASCADE, key_word_txt character varying(200) NOT NULL,score_weight int NOT NULL DEFAULT 0,comment text, CONSTRAINT key_word_tbl_pk UNIQUE(question_id, key_word_txt));
CREATE INDEX key_word_tbl_question_id_index ON key_word_tbl (question_id);
CREATE TABLE answered_item_tbl(tested_id bigint REFERENCES tested_question_tbl (tested_id) ON DELETE CASCADE,class_student_id int REFERENCES class_student_tbl (class_student_id) ON DELETE CASCADE,answered_item character varying(2),is_right int DEFAULT NULL,CONSTRAINT answered_item_tbl_pk PRIMARY KEY(tested_id, class_student_id, answered_item));
CREATE TABLE answered_txt_tbl(tested_id bigint REFERENCES tested_question_tbl (tested_id) ON DELETE CASCADE,class_student_id int REFERENCES class_student_tbl (class_student_id) ON DELETE CASCADE,answered_txt text NOT NULL,CONSTRAINT answered_txt_tbl_pk PRIMARY KEY(tested_id, class_student_id));
CREATE TABLE student_test_tbl (test_id bigint REFERENCES test_info_tbl (test_id) ON DELETE CASCADE,class_student_id int REFERENCES class_student_tbl (class_student_id) ON DELETE CASCADE,present int NOT NULL DEFAULT 0,score int,st_ts_comment text,tea_ts_comment text,sd_score float8 DEFAULT 0,sd_score_temp float8 DEFAULT 0,CONSTRAINT student_test_tbl_pk PRIMARY KEY(test_id, class_student_id));
CREATE TABLE answered_score_tbl(tested_id bigint REFERENCES tested_question_tbl (tested_id) ON DELETE CASCADE,class_student_id int REFERENCES class_student_tbl (class_student_id) ON DELETE CASCADE,score float8 DEFAULT NULL,sd_score float8 DEFAULT 0,CONSTRAINT answered_score_tbl_pk PRIMARY KEY(tested_id, class_student_id));