Note that there are some explanatory texts on larger screens.

plurals
  1. POForeign Key Not Populating with Primary Key Values
    primarykey
    data
    text
    <p>OK I have searched for an answer but am not finding it, maybe I am just not typing the question right so here goes nothing. I have 2 tables, both of my tables has an auto-generated PK. The PK from tables 2 is an FK in table 1. Since they are both auto-generated I assumed the FK in table 1 would populate with the value that is auto-generated from table 2 but it is not working. The FK in table 1 shows to be null. Here is my SQL code for creating table 1:</p> <pre><code>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), ) </code></pre> <p>and here is table 2:</p> <pre><code>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, ) </code></pre> <p>I also have some insert statements:</p> <pre><code>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'), ... </code></pre> <p>and:</p> <pre><code>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'), </code></pre> <p>Why is the FK value showing null when I query table 1?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload