Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sending values from one table to other..

 
indu iyengar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ?
 
Badal Chowdhary
Ranch Hand
Posts: 34
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
indu iyengar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 34
Eclipse IDE Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Indu,

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

Thanks,
Badal
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic