0
我有一個問題,我不知道如何解決它,我是SQL中的一個begginer。拆分MySQL並對其進行比較
我想顯示具有相同名字的老師的名字所有學生的名字,在數據庫中的老師的名字是一個單一的領域,但包含了2個邏輯域(名字和姓氏)
這是我的數據庫格式
CREATE TABLE Faculty (
Id INT NOT NULL PRIMARY KEY AUTO_INCREMENT
,NAME VARCHAR(50)
,Address VARCHAR(60)
,YearFounded YEAR
,Dean VARCHAR(50)
);
CREATE TABLE Specialty (
Id INT NOT NULL PRIMARY KEY auto_increment
,IdFaculty INT (11) NOT NULL
,NAME VARCHAR(50)
,FOREIGN KEY (IdFaculty) REFERENCES Faculty(Id)
);
CREATE TABLE Course (
Id INT NOT NULL PRIMARY KEY auto_increment
,IdSpecialty INT NOT NULL
,NAME VARCHAR(50)
,TeachingYear INT
,Semester INT
,Professor VARCHAR(50)
,< -- TEACHER
FOREIGN KEY (IdSpecialty) REFERENCES Specialty(Id)
);
CREATE TABLE Student (
Id INT NOT NULL PRIMARY KEY auto_increment
,< -- STUDENT
IdFaculty INT NOT NULL
,IdSpecialty INT NOT NULL
,CurrentYear INT
,StudyGroup VARCHAR(10)
,Semester INT
,Scholarship VARCHAR(2)
,FOREIGN KEY (IdFaculty) REFERENCES Faculty(Id)
,FOREIGN KEY (IdSpecialty) REFERENCES Specialty(Id)
);
CREATE TABLE StudentData (
Id INT NOT NULL PRIMARY KEY
,CNP CHAR(13)
,FirstName VARCHAR(30)
,LastName VARCHAR(30)
,Father VARCHAR(50)
,Mother VARCHAR(50)
,Address VARCHAR(200)
,Nationality VARCHAR(50)
);
CREATE TABLE Grade (
Id INT NOT NULL PRIMARY KEY auto_increment
,IdStudent INT NOT NULL
,IdCourse INT NOT NULL
,Grade INT
,ExamDate DATE
,FOREIGN KEY (IdStudent) REFERENCES Student(Id)
,FOREIGN KEY (IdCourse) REFERENCES Course(Id)
);
StudentData沒有外鍵? –