Reputation: 135
I am simply trying to make a table. The code I have is:
{
Connection.Open();
OleDbCommand Command = new OleDbCommand();
Command.Connection = Connection;
Command.CommandText = @"CREATE TABLE Login
(
Login_ID int NOT NULL PRIMARY KEY,
ID int FOREIGN KEY REFERENCES Stud_Rec(ID)
)";
Command.ExecuteNonQuery();
Connection.Close();
}
I get the following error:
Syntax error in CONSTRAINT clause
I believe my syntax should be all correct, and don't know what's wrong with my code. Any help would be appreciated.
Upvotes: 2
Views: 684
Reputation: 135
I have solved it as;
CREATE TABLE Login
(
Login_ID int NOT NULL PRIMARY KEY,
ID int,
FOREIGN KEY (ID) REFERENCES Stud_Rec(ID)
)
Upvotes: 0
Reputation: 204924
CREATE TABLE Login
(
Login_ID int NOT NULL PRIMARY KEY,
ID int,
FOREIGN KEY (ID) REFERENCES Stud_Rec(ID)
)
You missed a comma before foreign
and did not name the foreign key.
If you use a SQL tool to highlight the errors in your SQL code you find it way easier.
Upvotes: 2