はい、Classes
テーブルへの外部キー参照に複数の列を含めることで、それを強制できます。
create table Schools (
SchoolID int not null primary key,
Name varchar(30) not null unique
)
go
create table Classes (
ClassID int not null primary key,
SchoolID int not null foreign key references Schools (SchoolID),
Name varchar(30) not null,
constraint UQ_Class_Schools UNIQUE (ClassID,SchoolID),
constraint UQ_Class_Names UNIQUE (SchoolID,Name)
)
go
create table Students (
StudentID int not null primary key,
SchoolID int not null foreign key references Schools (SchoolID),
ClassID int not null,
Name varchar(95) not null,
constraint FK_Student_Classes FOREIGN KEY (ClassID,SchoolID) references Classes (ClassID,SchoolID)
)
好みに応じて、両方のテーブルの列で外部キーを宣言することもできます。ClassID