Professional Web Applications Themes

primary key query - MySQL

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

  1. #1

    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

    roohbir Guest

  2. #2

    Default Re: primary key query

    On Mar 21, 11:54 am, "roohbir" <com> wrote: 

    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.

    strawberry Guest

  3. #3

    Default Re: primary key query

    On Mar 21, 5:01 am, "strawberry" <com> wrote: 






    >
    > 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.[/ref]

    Thanks for the reply Strawberry.
    The add_id has to be exactly one more than the highest add_id.
    Ros

    roohbir Guest

  4. #4

    Default Re: primary key query

    On 21 Mar, 12:33, "roohbir" <com> wrote: 
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]


    >
    > 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 -[/ref]

    Do you delete rows from this table? If not then auto-increment will go
    up in ones from your highest id.

    Captain Guest

  5. #5

    Default Re: primary key query

    On Mar 21, 5:34 am, "Captain Paralytic" <com>
    wrote: 
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]


    >
    > Do you delete rows from this table? If not then auto-increment will go
    > up in ones from your highest id.[/ref]

    No I don't delete rows from this table.

    roohbir Guest

  6. #6

    Default Re: primary key query

    On 21 Mar, 13:13, "roohbir" <com> wrote: 
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]
    > [/ref]

    >
    > No I don't delete rows from this table.- Hide quoted text -
    >
    > - Show quoted text -[/ref]

    Then auto-increment should do OK for you.

    Captain Guest

Similar Threads

  1. Primary Scratch & Windows Primary Paging file?
    By Tommy Oberst in forum Adobe Photoshop 7, CS, CS2 & CS3
    Replies: 14
    Last Post: April 15th, 10:26 PM
  2. query to find primary key
    By roohbir in forum MySQL
    Replies: 4
    Last Post: March 20th, 10:00 PM
  3. Primary Key
    By Javot in forum FileMaker
    Replies: 2
    Last Post: January 25th, 01:17 AM
  4. Add primary key
    By Simon Gorski in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: January 20th, 11:00 PM
  5. Get Primary Key
    By Leon Shaw in forum ASP.NET General
    Replies: 2
    Last Post: July 21st, 12:03 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139