0

我有以下代码:

 declare c cursor for
            select
                id_user_V3
                ,device_type
                ,4
                ,notfication_mode
                ,t1.device_token
                ,registration_date
                ,rank
                ,1
            from audiv2.dbo.mya_webservice_device_token t1
                join migr.asoc_V2_glb_user t2 on t1.user_id = t2.id_user_V2

        open c
        fetch next from c into @id_user_v3,@type,@application_id,@notiffication,@device_tooken,@creation_date,@rang,@status
        while @@FETCH_STATUS=0
            begin

                set @device_id = (ISNULL((SELECT MAX(id_device) FROM usr_device)+1,1))

                SET IDENTITY_INSERT usr_device ON

                insert into usr_device values
                (
                    @device_id
                    ,@id_user_v3
                    ,@type
                    ,@application_id
                    ,@notiffication
                    ,@device_tooken
                    ,@creation_date
                    ,@rang
                    ,@status
                )
                SET IDENTITY_INSERT usr_device OFF

                fetch next from c into @id_user_v3,@type,@application_id,@notiffication,@device_tooken,@creation_date,@rang,@status
            end

        close c
        deallocate c 

我得到的错误是:

只有在使用列列表并且 IDENTITY_INSERT 为 ON 时,才能为表 'usr_device' 中的标识列指定显式值。

我该如何解决这个问题?

提前致谢

4

1 回答 1

0

您需要在 INSERT 子句中明确提及所有列名

插入 usr_device (col1, col2,...) 值

于 2012-11-07T17:15:26.940 回答