我在这里不知所措,所以任何帮助将不胜感激。这是我正在运行的三个查询:
CREATE TABLE Contact
(ContactID VARCHAR(10) NOT NULL,
ContactCompanyName VARCHAR(80),
ContactFirstName VARCHAR(30),
ContactLastName VARCHAR(30),
EmployeeID VARCHAR(15),
CONSTRAINT Contact_PK PRIMARY KEY (ContactID));
GO
CREATE TABLE CompanyRepresentative
(EmployeeID VARCHAR(15) NOT NULL,
RepFirstName VARCHAR(30),
RepLastName VARCHAR(30),
CONSTRAINT CompanyRepresentative_PK PRIMARY KEY (EmployeeID));
GO
其次是:
ALTER TABLE Contact
ADD CONSTRAINT fk_EmployeeID1
FOREIGN KEY(EmployeeID)REFERENCES CompanyRepresentative(EmployeeID);
GO
最后:
INSERT dbo.Contact (ContactID, ContactCompanyName, ContactFirstName,
ContactLastName)
VALUES
('PC7432', 'Krueger Bakeries', 'Brian', 'Jones'),
('PC5317', 'Advanced Data Storage', 'Mark', 'Pulley'),
('PC2931', 'M&D Graphics and Design', 'Mike', 'Dorris'),
('PC1753', 'Apex Digital Solutions', 'Janice', 'Becker'),
('PC8527', 'Infensus Consultants', 'Narbeth', 'Pokrehl');
GO
INSERT dbo.CompanyRepresentative (EmployeeID, RepFirstName, RepLastName)
VALUES
('TBOC53297', 'Mike', 'Hartman'),
('TBOC32781', 'Lynn', 'Kynes'),
('TBOC12783', 'Jason', 'McCann'),
('TBOC43971', 'Susan', 'Mueller'),
('TBOC29753', 'Greg', 'Krebs');
GO
当我跑
select * from Contact
EmployeeID 字段不显示表 dbo.CompanyRepresentative 中外键 EmployeeID 的值,而是显示“NULL”。我错过了什么?