让我们简单点:
USE Example1
CREATE TABLE Person
(PersonID int PRIMARY KEY IDENTITY(1,1),
FirstName nchar(20) NOT NULL,
LastName nchar(20) NOT NULL,
Salary money NOT NULL
)
CREATE TABLE Student
(StudentID int PRIMARY KEY IDENTITY(1,1),
FirstName nchar(20) NOT NULL,
LastName nchar(20) NOT NULL,
FatherID int NOT NULL,
MotherID int NOT NULL,
CONSTRAINT fk_Student_FatherID FOREIGN KEY (FatherID)
REFERENCES Person(PersonID),
CONSTRAINT fk_Student_MotherID FOREIGN KEY (MotherID)
REFERENCES Person(PersonID)
)
CREATE TABLE Registration
(RegistrationID int PRIMARY KEY IDENTITY(1,1),
StudentID int NOT NULL,
Date datetime NOT NULL,
MonthlyPayment ??????????
CONSTRAINT fk_Registration_StudentID FOREIGN KEY (StudentID)
REFERENCES Student(StudentID)
)
INSERT INTO Person VALUES ('John','Doe','1000')
INSERT INTO Person VALUES ('Mary','Poppins','800')
INSERT INTO Student VALUES ('Gary','Doe', 1, 2)
INSERT INTO Registration VALUES (1, getdate(),???)
我有一个学生要在学校进行注册,并且每月支付一笔款项,FatherSalary*0.5 + MotherSalary*0.5
但我不知道如何做到这一点。我是 SQL 新手,也许这很简单,我应该知道如何制作它,但我不知道,我需要帮助。