Megin
asked on
How do I create a composite key in SQL in Access?
I want to have a table with multiple primary keys (composite key?)
This is what I have:
I have also tried this:
Neither are working. I have another table that gets more complicated, with multiple foreign keys and primary keys.
I have lots of examples, but I am working in Access, which seems to make it more difficult.
Help!
This is what I have:
CREATE TABLE SubTaskOrders
(
[stoID] Counter PRIMARY KEY NOT NULL,
[TaskOrderID] Int PRIMARY KEY NOT NULL,
[stoNo] Char(2) NOT NULL,
[StoName] Varchar(100) NOT NULL,
FOREIGN KEY (TaskOrderID) REFERENCES TaskOrders (TaskOrderID)
);
I have also tried this:
CREATE TABLE SubTaskOrders
(
[stoID] Counter NOT NULL,
[TaskOrderID] Int NOT NULL,
[stoNo] Char(2) NOT NULL,
[StoName] Varchar(100) NOT NULL,
PRIMARY KEY (stoID, TaskOrderID)
FOREIGN KEY (TaskOrderID) REFERENCES TaskOrders (TaskOrderID)
);
Neither are working. I have another table that gets more complicated, with multiple foreign keys and primary keys.
I have lots of examples, but I am working in Access, which seems to make it more difficult.
Help!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That worked, but I can't see where it was different than my second example. What did you do? I know it had to be different, but how?
And, thank you!
And, thank you!
Only a small difference, you forgot to put a comma","
Between
PRIMARY KEY (stoID, TaskOrderID),
and
FOREIGN KEY (TaskOrderID) REFERENCES TaskOrders (TaskOrderID)
This kind of mistakes happens to all of us when we try to do something really fast.
:)
Between
PRIMARY KEY (stoID, TaskOrderID),
and
FOREIGN KEY (TaskOrderID) REFERENCES TaskOrders (TaskOrderID)
This kind of mistakes happens to all of us when we try to do something really fast.
:)
ASKER
Those little things kill me! No matter how hard I try to find them, I alway end up missing something.
Thank you!
Thank you!
CREATE TABLE SubTaskOrders
(
[stoID] Counter NOT NULL,
[TaskOrderID] Int NOT NULL,
[stoNo] Char(2) NOT NULL,
[StoName] Varchar(100) NOT NULL,
CONSTRAINT pk_stoID PRIMARY KEY (stoID, TaskOrderID)
FOREIGN KEY (TaskOrderID) REFERENCES TaskOrders (TaskOrderID)
);