Hello everyone,
I have a problem with my database.It worked until today when I tried to build it and it said that my db relationship is not good"SQL71516: The referenced table '[dbo].[Courses]' contains no primary or candidate keys that match the referencing column list in the foreign key. If the referenced column is a computed column, it should be persisted" and also "Error 159: EntityType 'DatabaseStudentsModel.Login' has no key defined. Define the key for this EntityType"In the second case,I already have the keys defined...These are my tables:
CREATE TABLE [dbo].[RegisterTeacher] (
[SNTeacher] INT NOT NULL,
[UserName] NVARCHAR (30) NOT NULL,
[pwd] INT NOT NULL,
[fullName] NVARCHAR (MAX) NOT NULL,
[courseID] INT NOT NULL,
[education] NVARCHAR (50) NULL,
PRIMARY KEY CLUSTERED ([SNTeacher]),
CONSTRAINT [FK_RegisterTeacher_ToTable] FOREIGN KEY ([courseID]) REFERENCES [Courses]([courseID])
);
CREATE TABLE [dbo].[Login] (
[SNTeacher] INT NULL,
[UserName] NVARCHAR (10) NOT NULL,
[pwd] INT NOT NULL,
PRIMARY KEY CLUSTERED ([pwd]),
CONSTRAINT [FK_Login_ToTable] FOREIGN KEY ([SNTeacher]) REFERENCES [dbo].[RegisterTeacher] ([SNTeacher])
);
CREATE TABLE [dbo].[Courses] (
[courseID] INT NOT NULL,
[courseName] NVARCHAR (MAX) NOT NULL,
[education] NVARCHAR (50) NOT NULL,
[SNTeacher] INT NOT NULL,
[ClassID] NVARCHAR (18) NULL,
PRIMARY KEY CLUSTERED ([courseID] ASC),
CONSTRAINT [FK_Courses_ToTable] FOREIGN KEY ([SNTeacher]) REFERENCES [dbo].[RegisterTeacher] ([SNTeacher])
);
CREATE TABLE [dbo].[ChildCourse] (
[courseID] INT NOT NULL,
[UserName] NVARCHAR (10) NOT NULL,
[sNr] INT NOT NULL,
PRIMARY KEY CLUSTERED ([courseID] ASC),
CONSTRAINT [FK_ChildCourse_ToTable] FOREIGN KEY ([sNr]) REFERENCES [Courses]([SNTeacher])
);
What should I do in order to get rid of the error and what did I do wrong when it came about establishing the relations between the tables?Thank you in advance!
What I have tried:
I have tried to change the PK and FK for Courses,Login and RegisterTeacher,but the database won't allow me to do anything,even if I change sth,the table won't alter.