[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Patrick

2/28/2007 9:08:00 PM

Hi Friends,
SQL2005

I am trying to insert into a table with identity column:

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[BulkMailExportJobLog](
[jobID] [int] IDENTITY(1,1) NOT NULL,
[BulkMailTypeID] [int] NOT NULL,
[startdate] [datetime] NOT NULL,
[enddate] [datetime] NOT NULL,
[insertdate] [datetime] NOT NULL CONSTRAINT
[DF_BulkMailExportJobLog_insertdate] DEFAULT (getdate()),
[status] [int] NOT NULL CONSTRAINT [DF_BulkMailExportJobLog_status]
DEFAULT ((0)),
[filename] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
CONSTRAINT [PK_BulkMailExportJobLog] PRIMARY KEY CLUSTERED
(
[jobID] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
GO

using this script :


SET IDENTITY_INSERT dbo.BulkMailExportJobLog ON
go
insert into clsql43.mnfileexchange.dbo.BulkMailExportJobLog
select * from clsql44.mnfileexchange.dbo.BulkMailExportJobLog
where jobid not in (select jobid from
clsql43.mnfileexchange.dbo.BulkMailExportJobLog)
go

but getting this error again :
Msg 8101, Level 16, State 1, Line 1
An explicit value for the identity column in table
'clsql43.mnfileexchange.dbo.BulkMailExportJobLog' can only be
specified when a column list is used and IDENTITY_INSERT is ON.


isn't SET IDENTITY_INSERT table ON suposed to take care of this ?

Thanks in advance ,
Pat

2 Answers

Aaron [SQL Server MVP]

2/28/2007 9:13:00 PM

0

Like the error suggests, you need to specify a column list. You can't use
the lazy shorthand INSERT table SELECT you need to say INSERT table(col1,
col2) SELECT col1, col2 FROM ...

--
Aaron Bertrand
SQL Server MVP
http://www.sq...
http://www.aspfa...




"Pat" <PatrickAlexander.email@gmail.com> wrote in message
news:1172696873.538302.318290@m58g2000cwm.googlegroups.com...
> Hi Friends,
> SQL2005
>
> I am trying to insert into a table with identity column:
>
> SET ANSI_NULLS ON
> GO
> SET QUOTED_IDENTIFIER ON
> GO
> SET ANSI_PADDING ON
> GO
> CREATE TABLE [dbo].[BulkMailExportJobLog](
> [jobID] [int] IDENTITY(1,1) NOT NULL,
> [BulkMailTypeID] [int] NOT NULL,
> [startdate] [datetime] NOT NULL,
> [enddate] [datetime] NOT NULL,
> [insertdate] [datetime] NOT NULL CONSTRAINT
> [DF_BulkMailExportJobLog_insertdate] DEFAULT (getdate()),
> [status] [int] NOT NULL CONSTRAINT [DF_BulkMailExportJobLog_status]
> DEFAULT ((0)),
> [filename] [varchar](100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
> CONSTRAINT [PK_BulkMailExportJobLog] PRIMARY KEY CLUSTERED
> (
> [jobID] ASC
> )WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
> ) ON [PRIMARY]
>
> GO
> SET ANSI_PADDING OFF
> GO
>
> using this script :
>
>
> SET IDENTITY_INSERT dbo.BulkMailExportJobLog ON
> go
> insert into clsql43.mnfileexchange.dbo.BulkMailExportJobLog
> select * from clsql44.mnfileexchange.dbo.BulkMailExportJobLog
> where jobid not in (select jobid from
> clsql43.mnfileexchange.dbo.BulkMailExportJobLog)
> go
>
> but getting this error again :
> Msg 8101, Level 16, State 1, Line 1
> An explicit value for the identity column in table
> 'clsql43.mnfileexchange.dbo.BulkMailExportJobLog' can only be
> specified when a column list is used and IDENTITY_INSERT is ON.
>
>
> isn't SET IDENTITY_INSERT table ON suposed to take care of this ?
>
> Thanks in advance ,
> Pat
>


Erland Sommarskog

2/28/2007 11:21:00 PM

0

Pat (PatrickAlexander.email@gmail.com) writes:
> SET IDENTITY_INSERT dbo.BulkMailExportJobLog ON
> go
> insert into clsql43.mnfileexchange.dbo.BulkMailExportJobLog
> select * from clsql44.mnfileexchange.dbo.BulkMailExportJobLog
> where jobid not in (select jobid from
> clsql43.mnfileexchange.dbo.BulkMailExportJobLog)
> go
>
> but getting this error again :
> Msg 8101, Level 16, State 1, Line 1
> An explicit value for the identity column in table
> 'clsql43.mnfileexchange.dbo.BulkMailExportJobLog' can only be
> specified when a column list is used and IDENTITY_INSERT is ON.
>
>
> isn't SET IDENTITY_INSERT table ON suposed to take care of this ?

Seems to me that you are inserting into a table on a linked server, but
you SET command is for a table in the local database. You would have to
say:

SET IDENTITY_INSERT clsql43.mnfileexchange.dbo.BulkMailExportJobLog

But I would not expect that to work.

The easy way would be stop using IDENTITY, but roll your own. Then
you would not have this problem.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/...
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/...