jimfog Posted September 26, 2012 Share Posted September 26, 2012 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 More sharing options...
birbal Posted September 26, 2012 Share Posted September 26, 2012 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 More sharing options...
jimfog Posted October 31, 2012 Author Share Posted October 31, 2012 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 More sharing options...
justsomeguy Posted October 31, 2012 Share Posted October 31, 2012 Autoincrement can only apply to a column that is a key, but it doesn't need to be the primary key. Link to comment Share on other sites More sharing options...
jimfog Posted October 31, 2012 Author Share Posted October 31, 2012 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 More sharing options...
justsomeguy Posted October 31, 2012 Share Posted October 31, 2012 Indexes and keys are the same thing. http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html Link to comment Share on other sites More sharing options...
jimfog Posted October 31, 2012 Author Share Posted October 31, 2012 got it Link to comment Share on other sites More sharing options...
jimfog Posted November 1, 2012 Author Share Posted November 1, 2012 (edited) 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 November 1, 2012 by jimfog Link to comment Share on other sites More sharing options...
justsomeguy Posted November 1, 2012 Share Posted November 1, 2012 All indexes have a name, that's how you refer to them after you make them. Link to comment Share on other sites More sharing options...
jimfog Posted November 1, 2012 Author Share Posted November 1, 2012 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 More sharing options...
justsomeguy Posted November 1, 2012 Share Posted November 1, 2012 If you have an index that spans multiple columns it is easier to refer to it with a short name. It's just for convenience. Link to comment Share on other sites More sharing options...
jimfog Posted November 1, 2012 Author Share Posted November 1, 2012 Is it going to help when performing queries? Link to comment Share on other sites More sharing options...
birbal Posted November 1, 2012 Share Posted November 1, 2012 (edited) 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 November 1, 2012 by birbal Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now