Win a copy of Spring in Action (5th edition) this week in the Spring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

insert or update???  RSS feed

 
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess this is a rocky question:

I have a table with 3 elements:

1. name
2. age
3. GPA

there's a gui and the user update the infomraiton on a weekly basis.
the table above has no primery key. and it can contain:

Dan 23 3.4
Dan 22 3.0
Gil 21 3.3

etc

So, the question is this:
say the user has entered the information for the first time - I'll use INSERT but what if he only UPDATE the info???

how can i tell if this is his first time or not?
 
Marshal
Posts: 67163
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is there no primary key? Without a primary key your table is hopelessly hobbled.
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
becuase the name is not unique and there could be many instances of the same name.

Dan 23 3.4
Dan 22 3.0
Gil 21 3.3


if Dan is uniqe i will not be able to set the second line.
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you still need some sort of an ID for the row ex

id name age gpa
1 dan 23 3.0
2 dan 20 2.8
3 mike 21 3.3

then if you want to update you do it like this

update table set name=dan, age=23, gpa=3.1 where id = 2;

if you did it like this

update table set name=dan, age=23, gpa=3.1 where name = dan;
it would change all data where the name is dan, this would create bad data.

you can set up the id field using a sequence (in oracle) or an auto-increment in mysql


no offence at all, but it seems you are pretty new to databases and sql, might i suggest a GREAT site to get you started.

www.sqlcourse.com and after you get through that www.sqlcourse2.com

these helped me when I was just starting out, they let you build a database on there server as you are going thorough the course. Best part is that you never have to leave the page!

-Bob

[ November 15, 2004: Message edited by: Bob Rocks ]
[ November 15, 2004: Message edited by: Bob Rocks ]
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks bob - great site
 
Bob Rocks
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
no problem, glad I could help! I remember when I was just getting started and that site was a huge help! If you need any more help, feel free to let me know, I would be more than happy to lend a hand.

-Bob
 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bob,

I solved the issue according to your recommendation .
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!