Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2004-03-28
8
Medium Priority
?
15,543 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 200 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

885 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