Solved

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

Posted on 2004-03-28
8
15,512 Views
Last Modified: 2011-08-18
There are 2 table, table "user_table_a" and table "user_table_b", which are the same except that table "user_table_b" has 1 more column than table "user_table_a". I use this SQL statement to copy all of the content from table "user_table_a" to table "user_table_b". i get the error: "Insert Error: Column name or number of supplied values does not match table definition."

SQL statement: insert into user_table_b select * from user_table_a

Would somebody please tell me how to solve ? THanks
0
Comment
Question by:mikekwok
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 34

Accepted Solution

by:
arbert earned 50 total points
ID: 10700903
If the columns don't match, you need to explicitly code the select/insert:

insert into user_table_b (column1,column2,column3)   select column1,column2,column3 from user_table_a
0
 
LVL 34

Expert Comment

by:arbert
ID: 10700906
Actually, the SELECT * would still work since you have less columns in that table.  Always a good idea to user the column names though (just in case someone decides to add a column later)....
0
 

Author Comment

by:mikekwok
ID: 10700926
Sorry that what I want to do is copy all of the content from table "user_table_B" to table "user_table_A". i get the error: "Insert Error: Column name or number of supplied values does not match table definition."

SQL statement: insert into user_table_a select * from user_table_b


Table B has 1 more column .....
WOuld u please help me to solve the problem? Thanks
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 34

Expert Comment

by:arbert
ID: 10701037
Like I said above--you have to explicitly list the columns--you can just say insert into--list the columns that you want to insert into--I don't know how I can state it any clearer.

In my above example, change column1, column2, column3 to be the columns that you want to insert into....
0
 

Author Comment

by:mikekwok
ID: 10701127
If there are 20 columns, I have to explicitly list the columns, rite? is there any method that I need not to explicit list the columns ? Since 20 columns I have to type in many characters. Just want to know if there is any "lazy" method to handle this problem.
0
 
LVL 34

Expert Comment

by:arbert
ID: 10701188
If the columns don't match exactly, yes, you have to code it your self....
0
 

Author Comment

by:mikekwok
ID: 10701205
Thanks
0
 
LVL 34

Expert Comment

by:arbert
ID: 10701212
This will help a bit--list of columns with a comma after each.  Just change user_table_b to what ever table you want the column list from:

select  column_name + ',' from information_schema.columns
where table_name='user_table_b'
order by ordinal_position
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question