Jump to content

primary keys


jimfog

Recommended Posts

I have a table where a column stores the output of a uniqid-meaning a random number that every time the function is called, it is different. I have set this to be the primary key of the table. Do I need to set it AUTO INCREMENT also? Or do you think maybe is better to create a separate column named primary and set this to auto increment?

Link to comment
Share on other sites

what does uniqid refers? if it is mean to be id to identify something uniqly then you dont need to set seperate column for ids. purpose should be clear though for each field. if you dont set auto increment in case it encounters same id in database it will throw error. if you don auto increment it and it encounters same id it will incerement by 1 from the largest id it have in the database.

Link to comment
Share on other sites

  • 1 month later...

As a sidenote and in relation to primary keys...if I set something as auto increment does that means THAT automatically gets to become a primary key. The above question does not relate in anyway with the uniqid example I mention above.

Link to comment
Share on other sites

Are there other keys also besides primary ones...to what you are referring to? Can you be specific?

Link to comment
Share on other sites

got it

Link to comment
Share on other sites

I found in the web this line of code which I am having difficulty in finding what exactly the constraint keyword does plus the value next to it: CONSTRAINT tb_pk PRIMARY KEY (ProviderID),I ran the above query(and as guess) it a column named ProviderID which is going to be also the primary key.The words though "CONSTRAINT tb_pk" seem to have any effect at all. Sorry if I am putting this question here-If I have to, I will create a new topic. It seems CONSTRAINED is used to give a name to a primary key, but why we would want to do that?

Edited by jimfog
Link to comment
Share on other sites

yes...but if I do not set a name using CONSTRAINT, the indexes still get name, the name of the column. What it the point of giving them a name of our choice-such as tb_pk in the example above?That is one thing,the other, what is the reason giving name to a primary key(again look at the example above). The name that the primary key will take...will be PRIMARY.

Link to comment
Share on other sites

Is it going to help when performing queries?

Link to comment
Share on other sites

you can check in "information_scheme" database for "table_constraints" how the keys are represented. the name used to identify keys uniquely in table scheme.

Is it going to help when performing queries?
it is more of need than performance. keys will work quite when you use multiple column for one keys.as example sometime you wants to use two column combination as unique. means column1 column2A BA AB AB A if you have unique constraint on column1 and column B the above values will be considered unique in each case(combination of both coulmn) Edited by birbal
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...