The four key tables in the database design of the online examination system require specific code examples
When designing the database of the online examination system, we need to consider the users and test questions , exams and scores and other different data tables. The structure and code examples of these four key tables are described in detail below.
The user table stores all registered user information, which can include username, password, name, gender, age, contact information and other fields . The following is a code example of the user table:
CREATE TABLE users ( user_id INT PRIMARY KEY AUTO_INCREMENT, username VARCHAR(50) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL, name VARCHAR(100) NOT NULL, gender VARCHAR(10), age INT, contact VARCHAR(100) );
The question table is used to store all exam question information, including test questions, options, Correct answer and other fields. The following is a code example for the test question table:
CREATE TABLE questions ( question_id INT PRIMARY KEY AUTO_INCREMENT, exam_id INT, question_text TEXT NOT NULL, option_a VARCHAR(255) NOT NULL, option_b VARCHAR(255) NOT NULL, option_c VARCHAR(255) NOT NULL, option_d VARCHAR(255) NOT NULL, answer CHAR(1) NOT NULL, FOREIGN KEY (exam_id) REFERENCES exams(exam_id) );
The exam table is used to store all exam information, including exam name, exam time, Fields such as exam duration. The following is a code example for the exam table:
CREATE TABLE exams ( exam_id INT PRIMARY KEY AUTO_INCREMENT, exam_name VARCHAR(100) NOT NULL, exam_date DATETIME NOT NULL, duration INT NOT NULL );
The score table is used to store the score information of each user after taking the exam, including the user ID, test ID, score and other fields. The following is a code example of the score table:
CREATE TABLE scores ( score_id INT PRIMARY KEY AUTO_INCREMENT, user_id INT, exam_id INT, score INT, FOREIGN KEY (user_id) REFERENCES users(user_id), FOREIGN KEY (exam_id) REFERENCES exams(exam_id) );
The above is an example of a key table in the database design of the online examination system. According to specific needs, the tables can be expanded and modified based on these basic tables to meet the functional and performance requirements of the system. At the same time, you also need to pay attention to establishing correct foreign key associations and indexes to improve query efficiency and data integrity.
Note: The above code example is a common design. The design of the specific database and table structure depends on the system requirements and the developer's specific implementation method.
The above is the detailed content of Four key tables in online examination system database design. For more information, please follow other related articles on the PHP Chinese website!