Solved

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

Posted on 2004-03-28
8
15,476 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
  • 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
 
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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Performance is the key factor for any successful data integration project, knowing the type of transformation that you’re using is the first step on optimizing the SSIS flow performance, by utilizing the correct transformation or the design alternat…
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

760 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

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now