Jump to content

Making An Auto Increment As Sequence


anggwaponi
 Share

Recommended Posts

hello to each and everyone :) the table i created has no define PRIMARY KEY, INCREMENT, UNIQUE, & Constraints.i would like to ask our very-well knowledgeable Moderator(s) and to our guest to assist me again in my self-learning activities.my table has already been created. in fact, it has now some data which through the guidance (like Dad "D"), i was able to refine its view or contents.now, how can i make the column P_Id to be on its increment value ... what are the command(s) or syntax? its like it has 10-data but only numbered from 1 to 8. i didn't put or included the number 9 and 10 when i inserted new data since i want it that if add or change, i can do it in 1-single move :)P_Id LName FName Address City zipcode Countryhoping to be guided accordingly.cheers! :)

Link to comment
Share on other sites

Who's the guest?I don't quite understand your question... do you want the P_Id column to be AUTO_INCREMENT?

Link to comment
Share on other sites

Who's the guest?I don't quite understand your question... do you want the P_Id column to be AUTO_INCREMENT?
hello Synook and good day too :) yes, that is really what i meant ... i want that the P_Id column to be AUTO_INCREMENT :) so how could it possibly be done ... what commands or syntax would i issued or used then?and as i said, the table has already existing data. like in that P_Id column ... it has 10-data numbered from top-to-bottom 1-8. i didn't put number 9 and 10 since i want to find out that if ever i make an auto increment ... i can see or check it myself what i'm working or doing really works.hope u can teach or assist me.cheers! :)
Link to comment
Share on other sites

to make it auto_increment, first you need to make it a key or in your case, a primary key by running the sql below:ALTER TABLE `test` ADD PRIMARY KEY ( `P_Id` );next, run the sql below:ALTER TABLE `test` CHANGE `P_Id` `P_Id` INT AUTO_INCREMENT note: change the table name `test` with your actual table name.hope that helps.

Link to comment
Share on other sites

to make it auto_increment, first you need to make it a key or in your case, a primary key by running the sql below:ALTER TABLE `test` ADD PRIMARY KEY ( `P_Id` );next, run the sql below:ALTER TABLE `test` CHANGE `P_Id` `P_Id` INT AUTO_INCREMENT note: change the table name `test` with your actual table name.hope that helps
hello virgil :) after i issued the command line ALTER TABLE `praktis_art_101` ADD PRIMARY KEY ( `P_Id` );i got a result that states:#1062 - Duplicate entry '0' for key 1 what those lines means?as a background info, the contents or data in column P_Id are numbered 1-8 from top-to-bottom and has a word NULL both for both 9 and 10. as i said, i didn't put number 9 and 10 since i want to find out that if ever i make an auto increment ... i can see or check it myself what i'm working or doing really works.
Link to comment
Share on other sites

You have to change those NULL values to something else. Remember, a primary key can't have duplicates!
hello Synookplease advise if my idea or my understanding in sql is correct.so does it mean that if i numbered the column P_Id like 1 2 3 4 5 6 NULL NULL NULL ... the command (am i using the right word) AUTO_INCREMENT will not work since their is a word NULL in the column.i thought that the command AUTO_INCREMENT will remove those NULL and will sequence the number from top-to-bottom ...likewise, if the column P_Id is numbered like 1 2 3 4 5 6 58 74 93, will it change to 1 2 3 4 5 6 7 8 9 if i used AUTO_INCREMENT ..kindly enlighten me.cheers!
Link to comment
Share on other sites

No... AUTO_INCREMENT will automatically create a higher number in that field for every new row inserted. However, an AUTO_INCREMENT field needs to be PRIMARY KEY, and you can't have duplicate values for PRIMARY KEY fields.

Link to comment
Share on other sites

No... AUTO_INCREMENT will automatically create a higher number in that field for every new row inserted. However, an AUTO_INCREMENT field needs to be PRIMARY KEY, and you can't have duplicate values for PRIMARY KEY fields
hello Synook :)so in-order for me to make the column P_Id defined as AUTO_INCREMENT ... i should change first those value that are NULL in the 9th and 10th portion (and so on .. and so forth) into its real number values? hmmmmmmi really thought that i can immediately make the column as an AUTO_INCREMENT. so does it mean also that i will make the column P_Id as its assigned PRIMARY KEY??likewise, what are the significance then about PRIMARY KEY, INCREMENT, UNIQUE, & Constraints ... can its function be interchanged???sorry if i sound like i just repeat what u said ... its not. i just want to make sure so at least i want to make sure and knowing that i'm just new to this aspect.in fact, how i wish i can alwys be on this forum for me to learned lots of stuff but i don't have much time since time also limit for me.cheers!
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
 Share

×
×
  • Create New...