现在你可能有几个问题,首先这两个结构不直接匹配,或者第二个被插入的表有一个标识列,所以即使可插入的列是直接匹配,被插入的表也有一个列比另一列多,并且不指定数据库假定您将尝试插入到该列.或者,您可能有相同数量的列,但其中一个是身份,因此无法插入(尽管我认为那将是不同的错误消息).I want to insert all the record from the back up table foo_bk into foo table without specific the columns.if i try this queryINSERT INTO fooSELECT *FROM foo_bki'll get error "Insert Error: Column name or number of supplied values does not match table definition."Is it possible to do bulk insert from one table to another without supply the column name?I've google it but can't seem to find an answer. all the answer require specific the columns. 解决方案 You should not ever want to do this. Select * should not be used as the basis for an insert as the columns may get moved around and break your insert (or worse not break your insert but mess up your data. Suppose someone adds a column to the table in the select but not the other table, you code will break. Or suppose someone, for reasons that surpass understanding but frequently happen, decides to do a drop and recreate on a table and move the columns around to a different order. Now your last_name is is the place first_name was in originally and select * will put it in the wrong column in the other table. It is an extremely poor practice to fail to specify columns and the specific mapping of one column to the column you want in the table you are interested in.Right now you may have several problems, first the two structures don't match directly or second the table being inserted to has an identity column and so even though the insertable columns are a direct match, the table being inserted to has one more column than the other and by not specifying the database assumes you are going to try to insert to that column. Or you might have the same number of columns but one is an identity and thus can't be inserted into (although I think that would be a different error message). 这篇关于SQL:将一个表中的所有记录插入到另一个表中,而不指定列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
09-05 02:36