Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • 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:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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?
 
Author and ninkuma
Marshal
Posts: 66783
168
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 .
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!