0

So I know that PK's can't be null, but I've been tasked with bulk inserting data from a .txt file(s) but the PK's in the files are NULL. I'm stumped and I don't actually know how to get around this.

The table creation:

CREATE TABLE BILLING (
FolioBillingID      smallint        NOT NULL        PRIMARY KEY,
FolioID             smallint        NOT NULL    FOREIGN KEY REFERENCES 
FOLIO(FolioID),
BillingCategoryID   smallint        NOT NULL    FOREIGN KEY REFERENCES 
BILLINGCATEGORY(BillingCategoryID),
BillingDescription  char(30)        NOT NULL,
BillingAmount       smallmoney      NOT NULL,
BillingItemQty      tinyint         NOT NULL,
BillingItemDate     date            NOT NULL)

Here's an example from the .txt file I need to insert:

|1|1|Room|99|1|5/2/2018
|1|2|Lodging Tax|11.14|1|5/2/2018
|1|1|Room|99|1|5/3/2018

And this is how I'm trying to bulk insert:

BULK INSERT BILLING FROM 'c:\stage\farms1-1\Billing.txt' 
WITH (FIELDTERMINATOR='|', FIRSTROW=1)

Is there a way around this? And if so, how would I go about it? Any help would be greatly appreciated! :)

SpaceGrape
  • 35
  • 5

1 Answers1

0

Make FolioBillingID autoincrement

kkica
  • 4,034
  • 1
  • 20
  • 40