HomeForum
Welcome, Guest

How do I import a record set and have the system assign the primary key based on the next value?
(1 viewing) (1) Guest
  • Page:
  • 1

TOPIC: How do I import a record set and have the system assign the primary key based on the next value?

How do I import a record set and have the system assign the primary key based on the next value? 1 year, 2 months ago #2119

  • Todd
  • OFFLINE
  • Fresh Boarder
  • Posts: 18
  • Karma: 0
Help me please!!!

How do I import a record set and have the system assign the primary key
based on the next value in the DB?

For instance I have a table:

Products.
Products.id
Products.partnumber
Products.desc

I want to upload a say 100 values of partnumber and desc
1234 FOO
4568 BAR
...


Let's say that the last value in the products. table is
ID : partnumber : desc
45886 : 4589 : FOOBAR

And when the upload/import is set to create new records, I want it to
automatically assign the next primary key value according to what the DB
"tells" it. I will not always have visibility into what the next value of
the key is so I can't include it in the upload without risking duplicate
keys.

How do I set the upload to do what I need?

Thanks!
T.

Re: How do I import a record set and have the system assign the primary key based on the next value? 1 year, 2 months ago #2120

  • admin
  • OFFLINE
  • Moderator
  • Posts: 2191
  • Karma: 12
Hi.

What is your target database?

Mike

Re: How do I import a record set and have the system assign the primary key based on the next value? 1 year, 2 months ago #2121

  • Todd
  • OFFLINE
  • Fresh Boarder
  • Posts: 18
  • Karma: 0
Mike

It is MSSQL

T

Re: How do I import a record set and have the system assign the primary key based on the next value? 1 year, 2 months ago #2122

  • admin
  • OFFLINE
  • Moderator
  • Posts: 2191
  • Karma: 12
Todd.

You can use identity field for you primary key

CREATE TABLE dbo.PRODUCTS
(
PRODUCT_ID int NOT NULL IDENTITY (1, 1),
PRODUCT varchar(50) NULL
) ON [PRIMARY]
GO

Mike

Re: How do I import a record set and have the system assign the primary key based on the next value? 1 year, 2 months ago #2123

  • Todd
  • OFFLINE
  • Fresh Boarder
  • Posts: 18
  • Karma: 0
Thanks a lot for your help. It turns out that apparently the database is "smart" enough to ignore what I put in the key field and it just assigns it the next appropriate key.

I have no idea what I'm doing by the way... Just playing with live data on a production website!

T
  • Page:
  • 1
Time to create page: 0.17 seconds

Testimonials

"Advanced ETL Processor it is the only software which treats our POP3 server as a database server."

Tom Barker,
Director of Information Technology

User Login

You only need to log in or register to use our support forum



Our customers

BP

BBC

HSBC


Databases we work with

Go to top