CREATE TABLE Thesis
(
ThesisNo numeric(8,0) NOT NULL,
AuthorID int NOT NULL,
EnstituteID int NOT NULL,
SupervisorID int NOT NULL,
Title nvarchar(100)NOT NULL,
Abstract nvarchar(500)NOT NULL,
Pages int NOT NULL,
SumbitDate datetime NOT NULL,
[Type] nchar(30) NOT NULL,
[Language] nchar(20) NOT NULL,
PRIMARY KEY (ThesisNo),
FOREIGN KEY (EnstituteID) REFERENCES Enstitute(EnstituteID),
FOREIGN KEY (AuthorID) REFERENCES Author(AuthorID),
FOREIGN KEY (SupervisorID) REFERENCES Supervisor(SupervisorID)
)
CREATE TABLE Person
(
PersonID int NOT NULL,
PersonFullName nvarchar(70) NOT NULL,
PRIMARY KEY (PersonID)
)
I use a Windows Forms application written in C#.
I take the author as a string, but when adding a foreign key to the thesis, I need to add that author's primary key so that I can access the contact table and find that person. How can I find out what is the primary key of the person name entered?
string query = "INSERT INTO Thesis (AuthorID,EnstituteID,SupervisorID,CoSupervisorID,Title,Abstract,Pages,SubmitDate,Type,Language)" +
"VALUES (@author,@enstitute,@supervisor,@cosupervisor,@title,@abstract,@pages,@submitdate,@type,@language) ";
AuthorID
or other ID members are int and foreign keys but the entered values are string @author @enstitute, @supervisor, @cosupervisor