Problem Inserting Record via Distributed Query

  • Is there any known problem with inserting a row via distributed query to table on another server where the table in question has an identity column?

    Here is the structure of the table I'm trying to write to:

    CREATE TABLE dbo.dba_debug

    (

    dbg_identity int IDENTITY,

    dbg_step int NULL,

    dbg_desc varchar(100) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,

    dbg_datetime datetime NULL

    )

    The query I'm using:

    INSERT INTO SERVER2.database.dbo.table

    SELECT1 as dbg_step,

    'Text String' as dbg_desc,

    GETDATE() as dbg_datetime

    ...generates the following error.

    Msg 213, Level 16, State 1, Line 2

    Column name or number of supplied values does not match table definition.

    If I run the query above on SERVER2 itself it runs fine and the identity is populated.

    Thanx...

  • Try to at least do this in all your insert statements. Relying on order can get you into trouble when schema changes down the road.

    INSERT INTO SERVER2.database.dbo.table (dbg_step, dbg_desc, dbg_datetime)

    SELECT 1 as dbg_step,

    'Text String' as dbg_desc,

    GETDATE() as dbg_datetime

    -Chuck

    @SQLGuyChuck

  • Thanks much. No idea why I didn't think of that.

    Plaid...

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply