Jump to content

Picking Unique ID


PupChow

Recommended Posts

Sorry if this is a very elementary question, but I just cannot seems to find the answer in the books I have (probably because it is very simple?) or online.

What is the best way to create a unique ID? This ID will be used to link up a couple tables, and I was adviced to not use Auto-number field. Is there a easy way to generate a unique number in PHP while it is inserting the data into the database?
Link to comment
Share on other sites

Something about it is hard to manage. I didn't really quite follow thought...

What I am trying to do in simple term is 2 tables:

Table1: ID, Name, Address, Phone
Table2: ID, Salary

And I am in the process of building PHP pages that will allow users to enter their own information and be put into the database.
Link to comment
Share on other sites

There's nothing about it that's hard to manage...every time a record is inserted into the db, it assigns it the next incremental id.

Potential table structure:
[code]
person
    ID
    Name
    Address
    Phone

workinfo
    ID
    personID
    Salary[/code]

sample query:

[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] Name, Address, Phone, Salary
[color=green]FROM[/color] [color=orange]person[/color] [color=green]LEFT[/color] [color=green]JOIN[/color] workinfo ON person.ID [color=orange]=[/color] workinfo.personID
[color=green]WHERE[/color] Name [color=orange]=[/color] [color=red]'Some Name'[/color] [!--sql2--][/div][!--sql3--]
Link to comment
Share on other sites

[!--quoteo(post=355172:date=Mar 14 2006, 08:17 PM:name=PupChow)--][div class=\'quotetop\']QUOTE(PupChow @ Mar 14 2006, 08:17 PM) [snapback]355172[/snapback][/div][div class=\'quotemain\'][!--quotec--]
do I also just join the table first if I want to delete a record?
[/quote]

No, you'll have to delete each of them.
Link to comment
Share on other sites

[!--quoteo(post=355175:date=Mar 14 2006, 08:22 PM:name=hitman6003)--][div class=\'quotetop\']QUOTE(hitman6003 @ Mar 14 2006, 08:22 PM) [snapback]355175[/snapback][/div][div class=\'quotemain\'][!--quotec--]
No, you'll have to delete each of them.
[/quote]

Would I need to do two different SQL queries for insert as well? Sorry, I am pretty new to this.
Link to comment
Share on other sites

I am quite sure you can manage with 1 SQL statement, but to be on the safe side you should definately use 2 unless you test it thoroughly.. although I really don't see why it wouldnt work with one.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.