473,322 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Indentity Insert

I'm doing a data transfer from Access to SQL Server, I wish to keep the
identity column (autonumber) values as all the data is already related. I
tried the first table append query including the identity column, it worked.
Was this fluke? Will it always work? I was under the impression that I would
have to issue a "set identity_insert on" before doing this. The SQL database
will have absolutely no data before the transfer routines are run.
Jul 20 '05 #1
15 11388
As long as there arent any duplicated values in what you are trying to
insert into the identity column you should have no problems.

You could also use Access' upsizing wizard to move the tables to SQL
server. This feature is available in A2k, I'm not sure about versions
below that.

http://www.cooldigitec.co.uk/njw/15-...SQLServer7.asp

Is an account of my upsizing experiences.

HTH
--

Nath
www.cooldigitec.co.uk
(Email mangling obvious)
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 20 '05 #2
"Nath Wilson" <ch*******@a0l.com> wrote in message
news:3f***********************@news.frii.net...
As long as there arent any duplicated values in what you are trying to
insert into the identity column you should have no problems.
OK Thanks.
You could also use Access' upsizing wizard to move the tables to SQL
server. This feature is available in A2k, I'm not sure about versions
below that.


It's an app rewrite, the tables are already there and slightly different.
Jul 20 '05 #3
I'd hope that "so*****@microsoft.com" should know their own software.

Pretty much real Pavel

For example John Smith wrote:

I'm doing a data transfer from Access to SQL Server, I wish to keep the
identity column (autonumber) values as all the data is already related. I
tried the first table append query including the identity column, it worked.
Was this fluke? Will it always work? I was under the impression that I would
have to issue a "set identity_insert on" before doing this. The SQL database
will have absolutely no data before the transfer routines are run.

Jul 20 '05 #4

No, you can't rely on the Identity field keeping the same number as
the autonumber field.
On Fri, 29 Aug 2003 12:25:28 +0100, "For example John Smith"
<so*****@microsoft.com> wrote:
I'm doing a data transfer from Access to SQL Server, I wish to keep the
identity column (autonumber) values as all the data is already related. I
tried the first table append query including the identity column, it worked.
Was this fluke? Will it always work? I was under the impression that I would
have to issue a "set identity_insert on" before doing this. The SQL database
will have absolutely no data before the transfer routines are run.

--
You're Not Losing More Hair, You're Gaining More Scalp.

Jul 20 '05 #5
"Pavel Romashkin" <pa*************@hotmail.com> wrote in message
news:3F***************@hotmail.com...
I'd hope that "so*****@microsoft.com" should know their own software.
It's a big company.
Pretty much real Pavel


A real what?
Jul 20 '05 #6
An update on this, it's now failing with the message:

Error 544 - [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert
explicit value for identity column in table 'zstblApplicationFunction' when
IDENTITY_INSERT is set to OFF. (ODBC.QueryDef)Error 3146 - ODBC--call
failed. (DAO.QueryDef)

In Profiler, the SQL trace shows:

<---------------------------------------------------
SET IDENTITY_INSERT "dbo"."zstblApplicationFunction" ON
go
exec sp_executesql N'INSERT INTO "dbo"."zstblApplicationFunction"
("ApplicationFunctionID","SortOrder","ParentApplic ationFunctionID","Applicat
ionFunctionName","DisplayName","Hyperlink","FormHe lpID","IsMenuItem","IsSubM
enuItem","IsEnforced","SysIsInsert","SysIsSelect", "SysIsUpdate","SysIsDelete
","SysIsExecute") VALUES
(@P1,@P2,@P3,@P4,@P5,@P6,@P7,@P8,@P9,@P10,@P11,@P1 2,@P13,@P14,@P15)', N'@P1
int,@P2 int,@P3 int,@P4 varchar(50),@P5 varchar(50),@P6 varchar(8000),@P7
int,@P8 bit,@P9 bit,@P10 bit,@P11 bit,@P12 bit,@P13 bit,@P14 bit,@P15 bit',
1, 3, NULL, 'SECURITYMENU', 'Security', NULL, NULL, 1, 0, 0, 0, 1, 0, 0, 0
go
IF @@TRANCOUNT > 0 ROLLBACK TRAN
go
---------------------------------------------------->

If I copy and paste that into Query Analyser it inserts the record. When
Access issues these commands to the server it fails. Odd.
Jul 20 '05 #7
Hi

The problems is the GO after SET IDENTITY_INSERT.. ON

I suggest you do this in a stored procedure.

John

"For example John Smith" <so*****@microsoft.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
An update on this, it's now failing with the message:

Error 544 - [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert
explicit value for identity column in table 'zstblApplicationFunction' when IDENTITY_INSERT is set to OFF. (ODBC.QueryDef)Error 3146 - ODBC--call
failed. (DAO.QueryDef)

In Profiler, the SQL trace shows:

<---------------------------------------------------
SET IDENTITY_INSERT "dbo"."zstblApplicationFunction" ON
go
exec sp_executesql N'INSERT INTO "dbo"."zstblApplicationFunction"
("ApplicationFunctionID","SortOrder","ParentApplic ationFunctionID","Applicat ionFunctionName","DisplayName","Hyperlink","FormHe lpID","IsMenuItem","IsSubM enuItem","IsEnforced","SysIsInsert","SysIsSelect", "SysIsUpdate","SysIsDelete ","SysIsExecute") VALUES
(@P1,@P2,@P3,@P4,@P5,@P6,@P7,@P8,@P9,@P10,@P11,@P1 2,@P13,@P14,@P15)', N'@P1 int,@P2 int,@P3 int,@P4 varchar(50),@P5 varchar(50),@P6 varchar(8000),@P7
int,@P8 bit,@P9 bit,@P10 bit,@P11 bit,@P12 bit,@P13 bit,@P14 bit,@P15 bit', 1, 3, NULL, 'SECURITYMENU', 'Security', NULL, NULL, 1, 0, 0, 0, 1, 0, 0, 0
go
IF @@TRANCOUNT > 0 ROLLBACK TRAN
go
---------------------------------------------------->

If I copy and paste that into Query Analyser it inserts the record. When
Access issues these commands to the server it fails. Odd.

Jul 20 '05 #8
"John Bell" <jb************@hotmail.com> wrote in message
news:3f*********************@reading.news.pipex.ne t...
Hi

The problems is the GO after SET IDENTITY_INSERT.. ON

I suggest you do this in a stored procedure.


I got another table with an Identity column and this works fine. The GO
doesn't seem to be a problem there (I think they're just put in by Profiler
anyway for the purpose of pasting into QA) and it works OK from QA with the
GOs in place..

A Stored procedure would be difficult as the data is coming from an Access
database although in the case of this particular table it comes from another
SQL database but I did try importing that one to Access and then running the
append query from the Access database. I can look at doing a SP for the ones
that do come from another SQL database (these are new ones added to the
application recently in the re-write) but since I'm on like table 3 out of
60 I'm not that confident the rest will go as smoothly as the first 2.

I'm pasting the troublesome table script below, this may provide a clue,
could be the self join FK that doesn't exist on any table I've transferred
thus far.

--- table script
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction_zstblApplicationFunction_ FK1]')
and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[zstblApplicationFunction] DROP CONSTRAINT
zstblApplicationFunction_zstblApplicationFunction_ FK1
GO

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction_zstblPermission_FK1]') and
OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[zstblPermission] DROP CONSTRAINT
zstblApplicationFunction_zstblPermission_FK1
GO

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[zstblApplicationFunction]
GO

CREATE TABLE [dbo].[zstblApplicationFunction] (
[ApplicationFunctionID] [int] IDENTITY (1, 1) NOT NULL ,
[SortOrder] [int] NULL ,
[ParentApplicationFunctionID] [int] NULL ,
[ApplicationFunctionName] [varchar] (50) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DisplayName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
,
[Hyperlink] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FormHelpID] [int] NULL ,
[IsMenuItem] [bit] NOT NULL ,
[IsSubMenuItem] [bit] NULL ,
[IsEnforced] [bit] NOT NULL ,
[SysIsInsert] [bit] NOT NULL ,
[SysIsSelect] [bit] NOT NULL ,
[SysIsUpdate] [bit] NOT NULL ,
[SysIsDelete] [bit] NOT NULL ,
[SysIsExecute] [bit] NOT NULL ,
[SysTimeStamp] [timestamp] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] WITH NOCHECK ADD
CONSTRAINT [zstblApplicationFunction_PK] PRIMARY KEY CLUSTERED
(
[ApplicationFunctionID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] ADD
CONSTRAINT [PrimaryKey_UC1] UNIQUE NONCLUSTERED
(
[ApplicationFunctionName]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

CREATE INDEX [IDX_ParentApplicationFunctionID] ON
[dbo].[zstblApplicationFunction]([ParentApplicationFunctionID]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO

CREATE INDEX [zstblApplicationFunction_AK2] ON
[dbo].[zstblApplicationFunction]([DisplayName]) WITH FILLFACTOR = 90 ON
[PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] ADD
CONSTRAINT [zstblApplicationFunction_zstblApplicationFunction_ FK1] FOREIGN
KEY
(
[ParentApplicationFunctionID]
) REFERENCES [dbo].[zstblApplicationFunction] (
[ApplicationFunctionID]
),
CONSTRAINT [zstblFormHelp_zstblApplicationFunction_FK1] FOREIGN KEY
(
[FormHelpID]
) REFERENCES [dbo].[zstblFormHelp] (
[FormHelpID]
)
GO

Jul 20 '05 #9
For example John Smith (so*****@microsoft.com) writes:
An update on this, it's now failing with the message:

Error 544 - [Microsoft][ODBC SQL Server Driver][SQL Server]Cannot insert
explicit value for identity column in table 'zstblApplicationFunction'
when IDENTITY_INSERT is set to OFF. (ODBC.QueryDef)Error 3146 -
ODBC--call failed. (DAO.QueryDef)

In Profiler, the SQL trace shows:


Hm, this is certainly a desprate idea, but check that you have the
same value for SPID for the commands.

Or, um, wait there is one more possibility. Under which user do you
run this from Access? And from Query Analyzer? SET IDENTITY_INSERT
is not permitted for plain users. Of course you should get an error
message for that too, and maybe you are if you sift through the
error messages.

And, oh, it would be appreciated if you fixed your name and e-mail
address.

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #10
Hi

Sorry, this is not transaction specific, but you should still put this in a
SP to solve the problems!

John

"For example John Smith" <so*****@microsoft.com> wrote in message
news:3f***********************@news.easynet.co.uk. ..
"John Bell" <jb************@hotmail.com> wrote in message
news:3f*********************@reading.news.pipex.ne t...
Hi

The problems is the GO after SET IDENTITY_INSERT.. ON

I suggest you do this in a stored procedure.
I got another table with an Identity column and this works fine. The GO
doesn't seem to be a problem there (I think they're just put in by

Profiler anyway for the purpose of pasting into QA) and it works OK from QA with the GOs in place..

A Stored procedure would be difficult as the data is coming from an Access
database although in the case of this particular table it comes from another SQL database but I did try importing that one to Access and then running the append query from the Access database. I can look at doing a SP for the ones that do come from another SQL database (these are new ones added to the
application recently in the re-write) but since I'm on like table 3 out of
60 I'm not that confident the rest will go as smoothly as the first 2.

I'm pasting the troublesome table script below, this may provide a clue,
could be the self join FK that doesn't exist on any table I've transferred
thus far.

--- table script
if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction_zstblApplicationFunction_ FK1]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[zstblApplicationFunction] DROP CONSTRAINT
zstblApplicationFunction_zstblApplicationFunction_ FK1
GO

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction_zstblPermission_FK1]') and
OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[zstblPermission] DROP CONSTRAINT
zstblApplicationFunction_zstblPermission_FK1
GO

if exists (select * from dbo.sysobjects where id =
object_id(N'[dbo].[zstblApplicationFunction]') and OBJECTPROPERTY(id,
N'IsUserTable') = 1)
drop table [dbo].[zstblApplicationFunction]
GO

CREATE TABLE [dbo].[zstblApplicationFunction] (
[ApplicationFunctionID] [int] IDENTITY (1, 1) NOT NULL ,
[SortOrder] [int] NULL ,
[ParentApplicationFunctionID] [int] NULL ,
[ApplicationFunctionName] [varchar] (50) COLLATE
SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[DisplayName] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[Hyperlink] [varchar] (512) COLLATE SQL_Latin1_General_CP1_CI_AS NULL ,
[FormHelpID] [int] NULL ,
[IsMenuItem] [bit] NOT NULL ,
[IsSubMenuItem] [bit] NULL ,
[IsEnforced] [bit] NOT NULL ,
[SysIsInsert] [bit] NOT NULL ,
[SysIsSelect] [bit] NOT NULL ,
[SysIsUpdate] [bit] NOT NULL ,
[SysIsDelete] [bit] NOT NULL ,
[SysIsExecute] [bit] NOT NULL ,
[SysTimeStamp] [timestamp] NULL
) ON [PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] WITH NOCHECK ADD
CONSTRAINT [zstblApplicationFunction_PK] PRIMARY KEY CLUSTERED
(
[ApplicationFunctionID]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] ADD
CONSTRAINT [PrimaryKey_UC1] UNIQUE NONCLUSTERED
(
[ApplicationFunctionName]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO

CREATE INDEX [IDX_ParentApplicationFunctionID] ON
[dbo].[zstblApplicationFunction]([ParentApplicationFunctionID]) WITH
FILLFACTOR = 90 ON [PRIMARY]
GO

CREATE INDEX [zstblApplicationFunction_AK2] ON
[dbo].[zstblApplicationFunction]([DisplayName]) WITH FILLFACTOR = 90 ON
[PRIMARY]
GO

ALTER TABLE [dbo].[zstblApplicationFunction] ADD
CONSTRAINT [zstblApplicationFunction_zstblApplicationFunction_ FK1] FOREIGN KEY
(
[ParentApplicationFunctionID]
) REFERENCES [dbo].[zstblApplicationFunction] (
[ApplicationFunctionID]
),
CONSTRAINT [zstblFormHelp_zstblApplicationFunction_FK1] FOREIGN KEY
(
[FormHelpID]
) REFERENCES [dbo].[zstblFormHelp] (
[FormHelpID]
)
GO

Jul 20 '05 #11
On Mon, 1 Sep 2003 20:11:40 +0000 (UTC) in comp.databases.ms-access,
Erland Sommarskog <so****@algonet.se> wrote:
And, oh, it would be appreciated if you fixed your name and e-mail
address.


I bet it's not the first time someone followed the instructions in
Outlook Express to the letter <g>

--
A)bort, R)etry, I)nfluence with large hammer.

(replace sithlord with trevor for email)
Jul 20 '05 #12
"Erland Sommarskog" <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
Hm, this is certainly a desprate idea, but check that you have the
same value for SPID for the commands.
Bang! Hit the nail squarely on the head, thanks for that pointer. It appears
that Access does issue a SET IDENTITY_INSERT ON command prior to the insert
but doesn't turn it off again afterward. My own passthrough query to turn it
off is running under a different SPID.

So it appears to be an Access bug.
Or, um, wait there is one more possibility. Under which user do you
run this from Access? And from Query Analyzer? SET IDENTITY_INSERT
is not permitted for plain users. Of course you should get an error
message for that too, and maybe you are if you sift through the
error messages.
sa. I did find an error message to that effect, level 16 but it appears
Access ignores anything lower than 18.
And, oh, it would be appreciated if you fixed your name and e-mail
address.


I don't wish to dwell on this but...
The fake email is clear, I don't want spam nor do I want to enter into email
correspondance, I've answered as many if not more questions in these groups
than I've asked and have fallen into the trap of taking problems into email
and then the other party expecting me to be their personal programming slave
or I have to ignore or tell the person outright that they're overstepping
the bounds of my generosity, either way it can end in tears (for them, not
me, you see it's for eveyone else's protection <g>). As for the name, one
could use an obvious fake, a fake that looks real or a real name (or a real
one that looks like an obvious fake), you still wouldn't know me from Adam.

Some people post anonymously because they know they are acting the fool and
even use remaillers to hide all trace (I don't BTW), others perhaps,
hypothetically (nudge wink) using a company account don't want bosses or
clients to see them asking questions on a public forum.

Jul 20 '05 #13
For example John Smith (so*****@microsoft.com) writes:
I don't wish to dwell on this but...
The fake email is clear, I don't want spam nor do I want to enter into
email correspondance, I've answered as many if not more questions in
these groups than I've asked and have fallen into the trap of taking
problems into email and then the other party expecting me to be their
personal programming slave or I have to ignore or tell the person
outright that they're overstepping the bounds of my generosity, either
way it can end in tears (for them, not me, you see it's for eveyone
else's protection <g>). As for the name, one could use an obvious fake,
a fake that looks real or a real name (or a real one that looks like an
obvious fake), you still wouldn't know me from Adam.


I also answer lot of questions, and sometimes get them in the mail
too, but I have never found it to be a problem with people asking for
too much.

A lot of people these days uses fake names and addresses, which in my
opinion is a pity, because being a long-timer in news I recall the days,
when replying by mail was the natural thing when the discussion was not
really of general interest. This is why I insist on using my real name and
mail address in public.

But even if you use a fake address, there are fake address which are less
appropriate than others. Unless you are a Microsoft emplyoess, I don't
you should use an fake address their domain.
--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #14
On Tue, 2 Sep 2003 20:44:17 +0000 (UTC), Erland Sommarskog
<so****@algonet.se> wrote:
But even if you use a fake address, there are fake address which are less
appropriate than others. Unless you are a Microsoft emplyoess, I don't
you should use an fake address their domain.


Or at least, add ".invalid" to the end of the email address, which is
the (RFC) accepted method for saying "this email address is fake".
--
You Will Become Rich And Famous Unless You Don't.

Jul 20 '05 #15
"Erland Sommarskog" <so****@algonet.se> wrote in message
news:Xn**********************@127.0.0.1...
But even if you use a fake address, there are fake address which are less
appropriate than others. Unless you are a Microsoft emplyoess, I don't
you should use an fake address their domain.


Noted.
Jul 20 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Flare | last post by:
Hi, When i eg. manually ad entries to a table and, cancels the insert Ms SQL increment the counter on the ID anyway. Is there a way to avoid this behavior? Regards Anders
2
by: Jashan | last post by:
Hi All I have a table in SQL Server with ID having indentity inrement by one. Table has not any trigger. Frequently ID in the table jumps. Any help !!! Thanks
3
by: Howard Hinnant | last post by:
I recently asked for a survey of multimap insert with hint behavior, in support of a paper I'm writing concerning lwg issue 233. My sincere thanks to Beman Dawes, Raoul Gough, Russell Hind, Bronek...
6
by: Mark P | last post by:
Some time ago I posted here about inserting into a set with a hint: ...
14
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
11
by: For example John Smith | last post by:
I'm doing a data transfer from Access to SQL Server, I wish to keep the identity column (autonumber) values as all the data is already related. I tried the first table append query including the...
4
by: Chris Kratz | last post by:
Hello all, We have run into what appears to be a problem with rules and subselects in postgres 7.4.1. We have boiled it down to the following test case. If anyone has any thoughts as to why...
2
by: Geoffrey KRETZ | last post by:
Hello, I'm wondering if the following behaviour is the correct one for PostGreSQL (7.4 on UNIX). I've a table temp_tab with 5 fields (f1,f2,f3,...),and I'm a launching the following request :...
3
by: MP | last post by:
Hi Posted this several hours ago to another ng but it never showed up thought i'd try here. using vb6, ado, .mdb, jet4.0, no access given table tblJob with field JobNumber text(10) 'The...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.