sggy_backup,sggy为两个sql数据库,想把sggy中 tab_gyyg 表的数据倒入到sggy_backup中的tab_gyyg表中,两张表的结构一样!!
sql语句如下:
insert into sggy_backup..tab_gyyg select * from  sggy..tab_gyyg可是系统提示 :
仅当使用了列的列表,并且 IDENTITY_INSERT 为 ON 时,才能在表 'sggy..tab_gyyg' 中为标识列指定显式值 我在sggy中tab_sggy中设置了dhno这个字段为种子,还有主键,是和这个有关把,那现在sql语句要怎么写啊 。急!

解决方案 »

  1.   


    看看MSDN的例子:SET IDENTITY_INSERT
    Allows explicit values to be inserted into the identity column of a table.Syntax
    SET IDENTITY_INSERT [ database. [ owner. ] ] { table } { ON | OFF }Arguments
    databaseIs the name of the database in which the specified table resides.ownerIs the name of the table owner.table Is the name of a table with an identity column.Res
    At any time, only one table in a session can have the IDENTITY_INSERT property set to ON. If a table already has this property set to ON, and a SET IDENTITY_INSERT ON statement is issued for another table, Microsoft® SQL Server™ returns an error message that states SET IDENTITY_INSERT is already ON and reports the table it is set ON for.If the value inserted is larger than the current identity value for the table, SQL Server automatically uses the new inserted value as the current identity value.The setting of SET IDENTITY_INSERT is set at execute or run time and not at parse time.Permissions
    Execute permissions default to the sysadmin fixed server role, and the db_owner and db_ddladmin fixed database roles, and the object owner.Examples
    This example creates a table with an identity column and shows how the SET IDENTITY_INSERT setting can be used to fill a gap in the identity values caused by a DELETE statement.-- Create products table.
    CREATE TABLE products (id int IDENTITY PRIMARY KEY, product varchar(40))
    GO
    -- Inserting values into products table.
    INSERT INTO products (product) VALUES ('screwdriver')
    INSERT INTO products (product) VALUES ('hammer')
    INSERT INTO products (product) VALUES ('saw')
    INSERT INTO products (product) VALUES ('shovel')
    GO-- Create a gap in the identity values.
    DELETE products 
    WHERE product = 'saw'
    GOSELECT * 
    FROM products
    GO-- Attempt to insert an explicit ID value of 3;
    -- should return a warning.
    INSERT INTO products (id, product) VALUES(3, 'garden shovel')
    GO
    -- SET IDENTITY_INSERT to ON.
    SET IDENTITY_INSERT products ON
    GO-- Attempt to insert an explicit ID value of 3
    INSERT INTO products (id, product) VALUES(3, 'garden shovel').
    GOSELECT * 
    FROM products
    GO
    -- Drop products table.
    DROP TABLE products
    GO
    See AlsoCREATE TABLEIDENTITY (Property)INSERTSET
      

  2.   

    解决了,是这个问题,表中存在自动累加的字段,这个字段作为标识,怪不得,我查了些资料,要在
    insert into sggy_backup..tab_gyyg select * from  sggy..tab_gyyg 这句前加上
     set indetity_insert  sggy_backup..tab_gyyg on 这样才可以对这个标识字段进行附值,谢谢两位了,结帐!