• Post Reply Bookmark Topic Watch Topic
  • New Topic

Insert in JSp

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
i am trying to insert just one field into a table which contains many fields. When i am executing this i am getting an error that the "destinational fields are not the same as the query results"
If anyone can tell me how i can insert just one field in a table of many fields.
Thank you and regards
vikram
 
James Swan
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
generally you can't just insert a single column into a table (unless the row only has one column), you have insert an entire row.
You might have to populate the other columns with dummy data (depending on their data type).
Updates can be done on single columns though.
James.
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
INSERT INTO table (field)
   SELECT field
   FROM othertable
   WHERE ...
This will only work if the other fields in the table are either NULL fields or have default values. In particular, the primary key field(s) (if any) need to be populated in some way unless they are autogenerated (SQL Server identity field, Oracle sequence in a trigger, PostgreSQL serial...)
- Peter
 
Pranit Saha
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually in this case number of records u r going to insert doesn't match with no.of columns.. To avoid this u need to specify the column names where u want to insert values.. like:
INSERT INTO TABLE(FIELDS) VALUES("..)
Hope this will solve ur prob..
Thanks
Pranit..
Originally posted by vikram nalagampalli:
"destinational fields are not the same as the query results"

 
vikram nalagampalli
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks one and all for your replies.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!