Unix Technical Forum

primary key query

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 ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:27 AM
roohbir
 
Posts: n/a
Default primary key query

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:27 AM
strawberry
 
Posts: n/a
Default Re: primary key query

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:27 AM
roohbir
 
Posts: n/a
Default Re: primary key query

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: primary key query

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:27 AM
roohbir
 
Posts: n/a
Default Re: primary key query

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:27 AM
Captain Paralytic
 
Posts: n/a
Default Re: primary key query

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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:16 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com