• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

sending values from one table to other..

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Ranch Hand
Posts: 34
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Indu,

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

Thanks,
Badal
reply
    Bookmark Topic Watch Topic
  • New Topic