OK Я искал ответ, но не нашел его, возможно, я просто не набираю вопрос правильно, поэтому здесь ничего не происходит. У меня есть 2 таблицы, обе мои таблицы имеют автоматически сгенерированный PK. ПК из таблиц 2 является FK в таблице 1. Поскольку они оба сгенерированы автоматически, я предположил, что FK в таблице 1 будет заполняться значением, которое автоматически генерируется из таблицы 2, но оно не работает. FK в таблице 1 имеет значение null. Вот мой SQL-код для создания таблицы 1:Иностранный ключ, не заполняемый основными значениями ключа
CREATE TABLE Employee_tbl (
EmployeeID int PRIMARY KEY IDENTITY,
LastName varchar(20) not null,
FirstName varchar(20) not null,
[Address] varchar(60)not null,
City varchar(20) not null,
[State] varchar(20) not null,
TelephoneAreaCode varchar(3) not null,
TelephoneNumber varchar(7) not null,
HireDate date,
Salary varchar(20) not null,
Gender char(1) not null,
Age varchar(3) not null,
JobID int FOREIGN KEY REFERENCES JobTitle_tbl(JobID),
)
и вот таблица 2:
create table JobTitle_tbl(
JobID int PRIMARY KEY IDENTITY,
EEO1Classification varchar(50) not null,
Job_title varchar(50) not null,
Job_description varchar(MAX) not null,
Exempt_nonexempt_status varchar(20) not null,
)
У меня также есть некоторые операторы вставки:
INSERT INTO Employee_tbl (LastName, FirstName, [Address], City, [State], TelephoneAreaCode,
TelephoneNumber, HireDate, Salary, Gender, Age)
Values
('Smith', 'John', '1234 Number Lane', 'Los Angeles', 'California', '555',
'8675309', '10/07/2003', '20,000.00', 'M', '50'),
...
и:
INSERT into JobTitle_tbl (EEO1Classification, Job_title, Job_description, Exempt_nonexempt_status)
VALUES
('Office/Clerical', 'Accounting Clerk', 'Computes classifies records and verifies numerical data for use in maintaining
accounting records. Essential Duties
1. Compiles and sorts documents, such as invoices and checks,
substantiating business transactions.
2. Verifies and posts details of business transactions, such as funds received
and disbursed, and totals accounts to ledgers or computer spreadsheets
and databases.
3. Audits invoices against purchase orders, researches discrepancies, and
approves for payment.
4. Computes and records charges, refunds, cost of lost or damaged goods,
freight charges, rentals and similar items.
5. Prepares vouchers, invoices, checks, account statements, reports and
other records and reviews for accuracy.
6. Reconciles general ledger accounts with various registers.
7. Reconciles bank statements.
8. Monitors accounts payable and receivable to ensure that payments are up
to date.
9. Assists employees, vendors, clients, or customers by answering questions
related to accounts, procedures, and services.
Required Qualifications and Experience
The accounting clerk must have excellent math and accounting skills, in addition
to the ability to use Quick Books software for maintaining records.', 'Non-Exempt'),
Почему значение FK показывает нулевое значение когда я запрашиваю таблицу 1?
Не могли бы вы уменьшить формулировку в своем вопросе? Также FK не генерируется автоматически. вам придется явно вставить его в дочернюю таблицу –