Solved

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

Posted on 2004-03-28
8
15,490 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Via a live example, show how to shrink a transaction log file down to a reasonable size.

777 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