CREATE TABLE teacher_tbl (teacher_id bigint PRIMARY KEY, teacher_nam character varying(50) NOT NULL DEFAULT '���L��', 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) DEFAULT '', comment text DEFAULT '', status int NOT NULL DEFAULT 1);
CREATE SEQUENCE tea_id_seq start 1 increment 1 maxvalue 99999 cycle cache 1;
INSERT INTO teacher_tbl VALUES (0, 'iitaka','toshibo666', 'mail', 'toshibo666', 'denwa', 'add', 'syozo', 'bikou', 1);
CREATE TABLE department_tbl (department_id int PRIMARY KEY, department_nam TEXT NOT NULL, comment TEXT);
CREATE SEQUENCE department_id_seq start 1 increment 1 maxvalue 99999 cycle cache 1;
CREATE TABLE grade_tbl (grade_id int PRIMARY KEY, grade_nam TEXT NOT NULL, comment TEXT);
CREATE SEQUENCE grade_id_seq start 1 increment 1 maxvalue 99999 cycle cache 1;
CREATE TABLE txt_level_tbl (txt_level_id int PRIMARY KEY, txt_level_nam TEXT NOT NULL, comment TEXT);
CREATE SEQUENCE txt_level_id_seq start 1 increment 1 maxvalue 99999 cycle cache 1;
CREATE TABLE difficulty_tbl (difficulty_id int PRIMARY KEY, difficulty_nam TEXT NOT NULL, comment TEXT);
CREATE SEQUENCE difficulty_id_seq start 1 increment 1 maxvalue 99999 cycle cache 1;
CREATE TABLE test_txt_tbl (text_id bigint PRIMARY KEY, text_title text NOT NULL DEFAULT '���L��', 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 DEFAULT NULL, department_id int DEFAULT NULL, comment text DEFAULT '',av_file text, av_repeat int DEFAULT 0,img_file text);
CREATE INDEX test_txt_tbl_level_index ON test_txt_tbl (level);
CREATE SEQUENCE text_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
CREATE TABLE question_tbl (question_id bigint PRIMARY KEY, 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 DEFAULT NULL, comment text DEFAULT '',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 INDEX question_tbl_level_index ON question_tbl (level);
CREATE SEQUENCE question_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
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 DEFAULT NULL, 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,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 DEFAULT NULL,sd_score float8,ave_score float8,participate_num int, full_score int);
CREATE SEQUENCE template_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
CREATE TABLE class_info_tbl (class_id bigint PRIMARY KEY, 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 DEFAULT '',comment text DEFAULT '',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 SEQUENCE class_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
CREATE TABLE student_tbl (student_id bigint PRIMARY KEY, 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 DEFAULT '���L��',belong text DEFAULT '���L��',comment text DEFAULT '���L��',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 SEQUENCE student_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
CREATE TABLE test_info_tbl (test_id bigint PRIMARY KEY, 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 DEFAULT NULL, 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 SEQUENCE test_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
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, 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 DEFAULT '',ave_score float8 DEFAULT 0,sddev float8 DEFAULT 0,CONSTRAINT tested_question_tbl_uni UNIQUE(question_type, test_id));
CREATE SEQUENCE tested_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
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, 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 DEFAULT '',teacher_comment text DEFAULT '',present int DEFAULT 0,status int DEFAULT 0,CONSTRAINT class_student_tbl_uni UNIQUE(student_id, class_id));
CREATE SEQUENCE class_st_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
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, question_id bigint NOT NULL REFERENCES question_tbl(question_id) ON DELETE CASCADE, key_word_txt text NOT NULL,score_weight int NOT NULL DEFAULT 0,comment text DEFAULT NULL, CONSTRAINT key_word_tbl_pk UNIQUE(question_id, key_word_txt));
CREATE SEQUENCE key_word_id_seq start 1 increment 1 maxvalue 999999999 cycle cache 1;
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 DEFAULT '',tea_ts_comment text DEFAULT '',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));