我有我要鏈接兩個表,我想表中的每一個人StudentID
與我的整個Questions
錶鏈接。如何將單個行從錶鏈接到一個整體單獨的表
我想創造的東西,讓我通過設置任意數量的從Question
表問題,個別Student
的StudentID
所以當學生跡象到他們的賬戶,他們可以查看已設置問題的探討。我想我可能需要添加Boolean
到我的問題表[set
]或類似的東西,我可以更新爲真,這意味着學生現在可以查看該問題。
我會提供我的表,也許有助於解釋多一點:
問題表(我想我要到StudentID
從該錶鏈接到的問題):
CREATE TABLE [dbo].[Questions] (
[QuestionID] INT IDENTITY (1, 1) NOT NULL,
[Actual answer] NVARCHAR (50) NULL,
[Question Space] NVARCHAR (50) NULL,
[Question Type] INT NULL,
PRIMARY KEY CLUSTERED ([QuestionID] ASC)
);
課程表:
CREATE TABLE [dbo].[Classes] (
[ClassSize] INT NULL,
[TeacherID] INT NOT NULL,
[StudentID] INT NOT NULL,
CONSTRAINT [PK_Classes] PRIMARY KEY CLUSTERED ([TeacherID] ASC, [StudentID] ASC),
CONSTRAINT [FK_Classes_StudentDetails] FOREIGN KEY ([StudentID]) REFERENCES [dbo].[StudentDetails] ([StudentID]),
CONSTRAINT [FK_Classes_TeacherDetails] FOREIGN KEY ([TeacherID]) REFERENCES [dbo].[TeacherDetails] ([TeacherID])
);
StudentDetails表
(我真的不認爲這是必要爲我提供此表,但我會反正):
CREATE TABLE [dbo].[StudentDetails] (
[StudentID] INT IDENTITY (1, 1) NOT NULL,
[Title] NVARCHAR (50) NULL,
[Username] NVARCHAR (50) NULL,
[Password] NVARCHAR (50) NULL,
[First Name] NVARCHAR (50) NULL,
[Last Name] NVARCHAR (50) NULL,
[Email Address] NVARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([StudentID] ASC)
);
您爲classes表複製了錯誤的SQL。 –