Super noob here at my wits end with Access 2010. I have some questions:
How do I create a child table in Access? I figured it'd be just a matter of defining the PK in the child table then referencing that PK as a FK to the parent table. Here's my sql code just in case I'm not making a bit of sense:
This is the end of my parent table which is Employee-
CONSTRAINT PKEmployee PRIMARY KEY (EmpNo) ,
CONSTRAINT FKPosNo FOREIGN KEY (PosNo) REFERENCES Position,
CONSTRAINT FKDeptNo FOREIGN KEY (DeptNo) REFERENCES Department )
Here's what I have for my child table, which is Salary. It's an Employee type-
CREATE TABLE Salary
( EmpNo CHAR (6) ,
OfficeNo CHAR (4) ,
SalaryAmount DOUBLE ,
CONSTRAINT PKEmpNo PRIMARY KEY (EmpNo),
CONSTRAINT FKEmpNo FOREIGN KEY (EmpNo) REFERENCES Employee )
When I run this code is gives me the "There is already a relationship named 'FKEmpNo' in the database." message. I'm not sure if this is on my end or Access'.
I'm also getting a syntax error when I try to declare 'SalaryAmount' as a DECIMAL. My code for it is:
(EmpNo CHAR (6) ,
OfficeNo CHAR (4) ,
SalaryAmount DECIMAL (7, 2) ,
CONSTRAINT PKEmpNo PRIMARY KEY (EmpNo),
CONSTRAINT FKEmpNo FOREIGN KEY (EmpNo) REFERENCES Employee )
The error highlights the first parenthesis. Can I even use DECIMAL type in access 2010? If not, what is the best way to represent a yearly income in Access 2010?
Please provide examples and explain to me like I'm a five year old. I'm trying wrap my mind around this database stuff without losing it.
FKEmpNoin some other table.FKSalarayEmpNoto distinguish the foreign key constraints from different tables.CREATE TABLEwithDECIMALmust be executed from ADO. It will not work when you attempt to execute the statement from DAO. If you're doing this from the Access query designer, be aware the query designer uses DAO "under the hood". All that aside, seems to me thatCURRENCYwould be the natural choice for a SalaryAmount field --- it's money, right?