使用SQL语句创建数据库:学生、教师、课程、作业和成绩表

当使用SQL语句创建一个数据库时,需要使用CREATE语句创建每个表,并定义表的列及其属性。

以下是创建示例数据库的SQL语句:

学生表(Student):

| StudentID | StudentName | Age | Gender | Email | |---|---|---|---|---| | 1 | John | 20 | Male | 'john@example.com' | | 2 | Emily | 22 | Female | 'emily@example.com' | | 3 | David | 19 | Male | 'david@example.com' | | 4 | Sophia | 21 | Female | 'sophia@example.com' | | 5 | James | 23 | Male | 'james@example.com' | | 6 | Olivia | 20 | Female | 'olivia@example.com' | | 7 | Ethan | 19 | Male | 'ethan@example.com' | | 8 | Ava | 22 | Female | 'ava@example.com' | | 9 | Benjamin | 21 | Male | 'benjamin@example.com' | | 10 | Mia | 20 | Female | 'mia@example.com' |

教师表(Teacher):

| TeacherID | TeacherName | Age | Gender | Email | |---|---|---|---|---| | 1 | Sarah | 30 | Female | 'sarah@example.com' | | 2 | Michael | 35 | Male | 'michael@example.com' | | 3 | Michelle | 32 | Female | 'michelle@example.com' | | 4 | Christopher | 33 | Male | 'christopher@example.com' | | 5 | Jennifer | 31 | Female | 'jennifer@example.com' | | 6 | Daniel | 34 | Male | 'daniel@example.com' | | 7 | Jessica | 29 | Female | 'jessica@example.com' | | 8 | Andrew | 36 | Male | 'andrew@example.com' | | 9 | Emily | 30 | Female | 'emily@example.com' | | 10 | Matthew | 35 | Male | 'matthew@example.com' |

课程表(Course):

| CourseID | CourseName | Description | |---|---|---| | 1 | Mathematics | 'Introduction to basic mathematical concepts and problem-solving techniques' | | 2 | English | 'Improve language skills through reading, writing, and speaking exercises' | | 3 | Science | 'Explore various scientific theories and conduct hands-on experiments' | | 4 | History | 'Study and analyze significant historical events and their impact' | | 5 | Computer Science | 'Learn programming languages and software development techniques' | | 6 | Art | 'Develop artistic skills and appreciation for different forms of art' | | 7 | Music | 'Explore different genres of music and learn to play musical instruments' | | 8 | Economics | 'Understand economic principles and analyze market trends' | | 9 | Psychology | 'Study human behavior and mental processes' | | 10 | Geography | 'Explore different regions and their physical features and cultural aspects' |

作业表(Assignment):

| AssignmentID | CourseID | TeacherID | AssignmentName | Description | |---|---|---|---|---| | 1 | 1 | 1 | 'Problem Set 1' | 'Solve mathematical problems' | | 2 | 2 | 2 | 'Essay Writing' | 'Write an essay on a given topic' | | 3 | 3 | 3 | 'Lab Experiment 1' | 'Perform a scientific experiment and document the results' | | 4 | 4 | 4 | 'Research Project' | 'Conduct research on a historical event and present findings' | | 5 | 5 | 5 | 'Programming Project' | 'Develop a software program' | | 6 | 6 | 6 | 'Art Portfolio' | 'Create and showcase artwork' | | 7 | 7 | 7 | 'Music Performance' | 'Perform a musical piece' | | 8 | 8 | 8 | 'Economic Analysis' | 'Analyze market trends and present findings' | | 9 | 9 | 9 | 'Case Study' | 'Analyze a psychological case study and provide insights' | | 10 | 10 | 10 | 'Research Paper' | 'Write a research paper on a geographical topic' |

成绩表(Grade):

| GradeID | StudentID | CourseID | AssignmentID | Grade | |---|---|---|---|---| | 1 | 1 | 1 | 1 | 90 | | 2 | 1 | 1 | 2 | 85 | | 3 | 1 | 2 | 3 | 95 | | 4 | 2 | 3 | 4 | 88 | | 5 | 2 | 4 | 5 | 92 | | 6 | 2 | 5 | 6 | 87 | | 7 | 3 | 6 | 7 | 90 | | 8 | 3 | 7 | 8 | 95 | | 9 | 3 | 8 | 9 | 91 | | 10 | 4 | 9 | 10 | 89 |

SQL语句:

-- 创建学生表
CREATE TABLE Student (
  StudentID INT PRIMARY KEY,
  StudentName VARCHAR(50),
  Age INT,
  Gender VARCHAR(10),
  Email VARCHAR(50)
);

-- 创建教师表
CREATE TABLE Teacher (
  TeacherID INT PRIMARY KEY,
  TeacherName VARCHAR(50),
  Age INT,
  Gender VARCHAR(10),
  Email VARCHAR(50)
);

-- 创建课程表
CREATE TABLE Course (
  CourseID INT PRIMARY KEY,
  CourseName VARCHAR(50),
  Description VARCHAR(255)
);

-- 创建作业表
CREATE TABLE Assignment (
  AssignmentID INT PRIMARY KEY,
  CourseID INT,
  TeacherID INT,
  AssignmentName VARCHAR(50),
  Description VARCHAR(255),
  FOREIGN KEY (CourseID) REFERENCES Course(CourseID),
  FOREIGN KEY (TeacherID) REFERENCES Teacher(TeacherID)
);

-- 创建成绩表
CREATE TABLE Grade (
  GradeID INT PRIMARY KEY,
  StudentID INT,
  CourseID INT,
  AssignmentID INT,
  Grade INT,
  FOREIGN KEY (StudentID) REFERENCES Student(StudentID),
  FOREIGN KEY (CourseID) REFERENCES Course(CourseID),
  FOREIGN KEY (AssignmentID) REFERENCES Assignment(AssignmentID)
);

请注意,上述SQL语句只是示例,您可以根据实际需求和数据库引擎的要求进行相应的修改。

SQL数据库设计:学生、教师、课程、作业和成绩表

原文地址: https://www.cveoy.top/t/topic/SXA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录