dbTalk Databases Forums  

Converting PK to identitiy?

microsoft.public.sqlserver.dts microsoft.public.sqlserver.dts


Discuss Converting PK to identitiy? in the microsoft.public.sqlserver.dts forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
MG
 
Posts: n/a

Default Converting PK to identitiy? - 08-05-2003 , 11:19 PM






Derek,

There are a couple of ways to do this.
First, I would build the tables in SQL(Tables1) with
Identity and a PK on that value, if that is what you want.

I would then create yet another set of those same tables
(Tables2), without Identity and PK values.

Import the Access tables to the second set (Tables2) in
DTS.

Then put together a script in the DTS job that will load
Tables2 to Tables1 but turning off the Identity Insert
Option when loading but turn it back on when done. This
way, you can keep the key values and keep your
referential integrety. When you start inserting into SQL
via normal operations after your initial load, the
identity functionality will work fine.

The reason, I created a second set was the purpose of
being able to turn on and off the SET IDENTITY
functionality. Please review the SET IDENTITY in books on
line.
It should work something like this:

SET IDENTITY_INSERT MyProductinTable OFF
Insert Into MyProductinTable
Select * from MyTEMPTable
SET IDENTITY_INSERT MyProductinTable ON

I may have the OFF ON statements backwards but I think
you will get the picture.

Also, make sure you load the table in the correct order
for referential integrety.

Hope this helps. There are other ways of doing this too
but this is a start and should work - Ive done it many
times.


Quote:
-----Original Message-----
Hello,
I am in the process of converting an Access database to
SQL Server.
Since I could not get at @@identity from Access 97 in
code, some of
the PKs I put in a random #. While it is easy for tables
that do not
have detail tables to setup the column on SQL Server as
being identity
and just not bring over the values from the old PK, how
do I handle
the situation when there is a detail table joined by that
old PK?
Thanks in advance
Derek
.


Reply With Quote
  #2  
Old   
Derek Agar
 
Posts: n/a

Default Re: Converting PK to identitiy? - 08-06-2003 , 08:50 AM






MG,
From what you are saying is to not worry about the old values, just
use identity afterward.
I started to think about this some more. I was hoping that there was
an easy way to bring the data accross and then resort the PK after the
relational integrity is setup and then set the identity.
Thanks, I will think about this some more.
Derek

"MG" <megordontn (AT) sprintmail (DOT) com> wrote

Quote:
Derek,

There are a couple of ways to do this.
First, I would build the tables in SQL(Tables1) with
Identity and a PK on that value, if that is what you want.

I would then create yet another set of those same tables
(Tables2), without Identity and PK values.

Import the Access tables to the second set (Tables2) in
DTS.

Then put together a script in the DTS job that will load
Tables2 to Tables1 but turning off the Identity Insert
Option when loading but turn it back on when done. This
way, you can keep the key values and keep your
referential integrety. When you start inserting into SQL
via normal operations after your initial load, the
identity functionality will work fine.

The reason, I created a second set was the purpose of
being able to turn on and off the SET IDENTITY
functionality. Please review the SET IDENTITY in books on
line.
It should work something like this:

SET IDENTITY_INSERT MyProductinTable OFF
Insert Into MyProductinTable
Select * from MyTEMPTable
SET IDENTITY_INSERT MyProductinTable ON

I may have the OFF ON statements backwards but I think
you will get the picture.

Also, make sure you load the table in the correct order
for referential integrety.

Hope this helps. There are other ways of doing this too
but this is a start and should work - Ive done it many
times.


-----Original Message-----
Hello,
I am in the process of converting an Access database to
SQL Server.
Since I could not get at @@identity from Access 97 in
code, some of
the PKs I put in a random #. While it is easy for tables
that do not
have detail tables to setup the column on SQL Server as
being identity
and just not bring over the values from the old PK, how
do I handle
the situation when there is a detail table joined by that
old PK?
Thanks in advance
Derek
.


Reply With Quote
  #3  
Old   
mg
 
Posts: n/a

Default Re: Converting PK to identitiy? - 08-06-2003 , 10:48 AM



Derek,
Almost, I was trying to let you keep your values as the
Identity values as well as the primary keys. The trick I
used will do that. As I shared, I have done this for years
and it saves the original values as the keys and identity
as well as still provides you/users with the same values
that you/they saw before. As per your last sentence, you
could do something like that by simply making antoher field
that holds your old values as an attribute/reference that
does not really tie to anything - then let SQL build the
records with a new Identity field with a PK - just make
sure the data is sorted in the order before the load.
Hope this helps.

Quote:
-----Original Message-----
MG,
From what you are saying is to not worry about the old
values, just
use identity afterward.
I started to think about this some more. I was hoping
that there was
an easy way to bring the data accross and then resort the
PK after the
relational integrity is setup and then set the identity.
Thanks, I will think about this some more.
Derek

"MG" <megordontn (AT) sprintmail (DOT) com> wrote

Derek,

There are a couple of ways to do this.
First, I would build the tables in SQL(Tables1) with
Identity and a PK on that value, if that is what you
want.

I would then create yet another set of those same
tables
(Tables2), without Identity and PK values.

Import the Access tables to the second set (Tables2) in
DTS.

Then put together a script in the DTS job that will
load
Tables2 to Tables1 but turning off the Identity Insert
Option when loading but turn it back on when done. This
way, you can keep the key values and keep your
referential integrety. When you start inserting into SQL
via normal operations after your initial load, the
identity functionality will work fine.

The reason, I created a second set was the purpose of
being able to turn on and off the SET IDENTITY
functionality. Please review the SET IDENTITY in books
on
line.
It should work something like this:

SET IDENTITY_INSERT MyProductinTable OFF
Insert Into MyProductinTable
Select * from MyTEMPTable
SET IDENTITY_INSERT MyProductinTable ON

I may have the OFF ON statements backwards but I think
you will get the picture.

Also, make sure you load the table in the correct order
for referential integrety.

Hope this helps. There are other ways of doing this too
but this is a start and should work - Ive done it many
times.


-----Original Message-----
Hello,
I am in the process of converting an Access database
to
SQL Server.
Since I could not get at @@identity from Access 97 in
code, some of
the PKs I put in a random #. While it is easy for
tables
that do not
have detail tables to setup the column on SQL Server
as
being identity
and just not bring over the values from the old PK,
how
do I handle
the situation when there is a detail table joined by
that
old PK?
Thanks in advance
Derek
.

.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.