my dog learned polymorphism*
The moose likes Oracle/OAS and the fly likes sending values from one table to other.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Bookmark "sending values from one table to other.." Watch "sending values from one table to other.." New topic
Author

sending values from one table to other..

indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
Hi all, I want to send some columns values from one table to other in mysql.

table1 = courses1
table2 = courses

each table has primary key courseID.

when i used
insert into courses(courseID) select courseID from courses1
it works properly.../// courseID is a primary key..
but when I used the similar kind statement by changing the column names its not working and showing the error as

how to pass these values ?


thanks ,
Indu
Badal Chowdhary
Ranch Hand

Joined: Apr 26, 2011
Posts: 34

Hi Indu,

Primary key cannot be null. If you try insert data into a table that has a primary key, you have to insert value of primary key column.

Eg:
Courses (course_id, course_name, course_credits)
Courses1 (course_id, course_name, course_credits)

course_id is the primary key in both tables.
Now if you only insert a record with course_name or course_credits into either tables, you will get an error. This is because since you are not inserting course_id (primary key), it will have null value.

The whole point of primary key is to uniquely identify a row. If course_id is primary key in your table, you must not have any record where course_id is null.

Thanks,
Badal


Blog: http://badalchowdhary.wordpress.com/
Twitter: http://twitter.com/badalrocks
indu iyengar
Ranch Hand

Joined: Jul 30, 2010
Posts: 115
Thanks Badal for your reply.. But what my point is .. I already stored course_id primary key column values..

after that if I want to store other column values, then its not working.. will it doesnot take the corresponding values for the specific primary key ?..

I tried to store other columns by giving where condition with primary key , but still the problem is there...
Badal Chowdhary
Ranch Hand

Joined: Apr 26, 2011
Posts: 34

Hi Indu,

Could you provide a sample dataset that is giving you error?

Thanks,
Badal
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: sending values from one table to other..
 
Similar Threads
org.hibernate.NonUniqueObjectException
EJB to RDB (bottom-up) Mapping does not generate a primary key
many-to-many where middle table has extra fields
problem in one-to-many mapping
Does WLS 6.1 support EJB2.0