Solved

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

Posted on 2004-03-28
8
15,483 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

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 …
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
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.

867 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

16 Experts available now in Live!

Get 1:1 Help Now