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

前端 未结 12 1828
轮回少年
轮回少年 2020-11-29 04:33

In SQL server, I am trying to insert values from one table to another by using the below query:

delete from tblTable1

insert into tblTable1 select * from tb         


        
12条回答
  •  猫巷女王i
    2020-11-29 05:01

    Dropping the table was not an option for me, since I'm keeping a running log. If every time I needed to insert I had to drop, the table would be meaningless.

    My error was because I had a couple columns in the create table statement that were products of other columns, changing these fixed my problem. eg

    create table foo (
    field1 as int
    ,field2 as int
    ,field12 as field1 + field2 )
    
    create table copyOfFoo (
    field1 as int
    ,field2 as int
    ,field12 as field1 + field2)  --this is the problem, should just be 'as int'
    
    insert into copyOfFoo
    SELECT * FROM foo
    

提交回复
热议问题