This is a discussion on primary key query within the MySQL forums, part of the Database Server Software category; --> Hi, I have this table called address and I want to add 2 records in it. The thing is ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi, I have this table called address and I want to add 2 records in it. The thing is before adding the records, I have to make sure the 'add_id' column is unique, finding out the maximum 'add_id', and using the "maximum 'add_id' + 1" as the new 'add_id'. I don't really know how ne can check whether a column is a PK. For finding the maximum 'add_id' I think I could use max(add_id), and then add 1 to it. But writing a query is a bit confusing for me right now. Would be really thankful if somebody could help me here. Thanks ros |
| |||
| On Mar 21, 11:54 am, "roohbir" <ros...@gmail.com> wrote: > Hi, > > I have this table called address and I want to add 2 records in it. > The thing is before adding the records, I have to make sure the > 'add_id' column is unique, finding out the maximum 'add_id', and using > the "maximum 'add_id' + 1" as the new 'add_id'. > > I don't really know how ne can check whether a column is a PK. > > For finding the maximum 'add_id' I think I could use max(add_id), and > then add 1 to it. > > But writing a query is a bit confusing for me right now. > > Would be really thankful if somebody could help me here. > > Thanks > ros Does the add_id have to be exactly 1 more than the highest add_id, or does it just have to be higher than the highest add_id? If it's the latter then auto_increment will do what you want. |
| |||
| On Mar 21, 5:01 am, "strawberry" <zac.ca...@gmail.com> wrote: > On Mar 21, 11:54 am, "roohbir" <ros...@gmail.com> wrote: > > > > > Hi, > > > I have this table called address and I want to add 2 records in it. > > The thing is before adding the records, I have to make sure the > > 'add_id' column is unique, finding out the maximum 'add_id', and using > > the "maximum 'add_id' + 1" as the new 'add_id'. > > > I don't really know how ne can check whether a column is a PK. > > > For finding the maximum 'add_id' I think I could use max(add_id), and > > then add 1 to it. > > > But writing a query is a bit confusing for me right now. > > > Would be really thankful if somebody could help me here. > > > Thanks > > ros > > Does the add_id have to be exactly 1 more than the highest add_id, or > does it just have to be higher than the highest add_id? > > If it's the latter then auto_increment will do what you want. Thanks for the reply Strawberry. The add_id has to be exactly one more than the highest add_id. Ros |
| |||
| On 21 Mar, 12:33, "roohbir" <ros...@gmail.com> wrote: > On Mar 21, 5:01 am, "strawberry" <zac.ca...@gmail.com> wrote: > > > > > > > On Mar 21, 11:54 am, "roohbir" <ros...@gmail.com> wrote: > > > > Hi, > > > > I have this table called address and I want to add 2 records in it. > > > The thing is before adding the records, I have to make sure the > > > 'add_id' column is unique, finding out the maximum 'add_id', and using > > > the "maximum 'add_id' + 1" as the new 'add_id'. > > > > I don't really know how ne can check whether a column is a PK. > > > > For finding the maximum 'add_id' I think I could use max(add_id), and > > > then add 1 to it. > > > > But writing a query is a bit confusing for me right now. > > > > Would be really thankful if somebody could help me here. > > > > Thanks > > > ros > > > Does the add_id have to be exactly 1 more than the highest add_id, or > > does it just have to be higher than the highest add_id? > > > If it's the latter then auto_increment will do what you want. > > Thanks for the reply Strawberry. > The add_id has to be exactly one more than the highest add_id. > Ros- Hide quoted text - > > - Show quoted text - Do you delete rows from this table? If not then auto-increment will go up in ones from your highest id. |
| |||
| On Mar 21, 5:34 am, "Captain Paralytic" <paul_laut...@yahoo.com> wrote: > On 21 Mar, 12:33, "roohbir" <ros...@gmail.com> wrote: > > > > > On Mar 21, 5:01 am, "strawberry" <zac.ca...@gmail.com> wrote: > > > > On Mar 21, 11:54 am, "roohbir" <ros...@gmail.com> wrote: > > > > > Hi, > > > > > I have this table called address and I want to add 2 records in it. > > > > The thing is before adding the records, I have to make sure the > > > > 'add_id' column is unique, finding out the maximum 'add_id', and using > > > > the "maximum 'add_id' + 1" as the new 'add_id'. > > > > > I don't really know how ne can check whether a column is a PK. > > > > > For finding the maximum 'add_id' I think I could use max(add_id), and > > > > then add 1 to it. > > > > > But writing a query is a bit confusing for me right now. > > > > > Would be really thankful if somebody could help me here. > > > > > Thanks > > > > ros > > > > Does the add_id have to be exactly 1 more than the highest add_id, or > > > does it just have to be higher than the highest add_id? > > > > If it's the latter then auto_increment will do what you want. > > > Thanks for the reply Strawberry. > > The add_id has to be exactly one more than the highest add_id. > > Ros- Hide quoted text - > > > - Show quoted text - > > Do you delete rows from this table? If not then auto-increment will go > up in ones from your highest id. No I don't delete rows from this table. |
| ||||
| On 21 Mar, 13:13, "roohbir" <ros...@gmail.com> wrote: > On Mar 21, 5:34 am, "Captain Paralytic" <paul_laut...@yahoo.com> > wrote: > > > > > > > On 21 Mar, 12:33, "roohbir" <ros...@gmail.com> wrote: > > > > On Mar 21, 5:01 am, "strawberry" <zac.ca...@gmail.com> wrote: > > > > > On Mar 21, 11:54 am, "roohbir" <ros...@gmail.com> wrote: > > > > > > Hi, > > > > > > I have this table called address and I want to add 2 records in it. > > > > > The thing is before adding the records, I have to make sure the > > > > > 'add_id' column is unique, finding out the maximum 'add_id', and using > > > > > the "maximum 'add_id' + 1" as the new 'add_id'. > > > > > > I don't really know how ne can check whether a column is a PK. > > > > > > For finding the maximum 'add_id' I think I could use max(add_id), and > > > > > then add 1 to it. > > > > > > But writing a query is a bit confusing for me right now. > > > > > > Would be really thankful if somebody could help me here. > > > > > > Thanks > > > > > ros > > > > > Does the add_id have to be exactly 1 more than the highest add_id, or > > > > does it just have to be higher than the highest add_id? > > > > > If it's the latter then auto_increment will do what you want. > > > > Thanks for the reply Strawberry. > > > The add_id has to be exactly one more than the highest add_id. > > > Ros- Hide quoted text - > > > > - Show quoted text - > > > Do you delete rows from this table? If not then auto-increment will go > > up in ones from your highest id. > > No I don't delete rows from this table.- Hide quoted text - > > - Show quoted text - Then auto-increment should do OK for you. |