www.webdeveloper.com
Results 1 to 9 of 9

Thread: Primary Key

  1. #1
    Join Date
    Jul 2006
    Posts
    1

    Primary Key

    how do i initialise the primary key if i am using mysql instead of microsoft access?

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,326
    Not sure what you mean by "initialise". Primary key just means that the field in question must (1) be unique and (2) is indexed - there's really nothing to be initialised (that I'm aware of). If you're talking about an auto-incremented integer field, when defining the table you can set the starting auto-increment value by adding auto_increment=123 in the table options section at the end of the table definition.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Jul 2006
    Posts
    36
    Once you give a field the property "primary key", it immediately 'gets into play'. Nothing more is needed.

    This is how MySQL works, and every other RDBMS I am familiar with.
    HumanDoorway - free CAPTCHA service, no code needed

  4. #4
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Quote Originally Posted by thoughtcube
    This is how MySQL works, and every other RDBMS I am familiar with.
    Actually you're supposed to have the capabilities of turning off the keys whenever you want.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  5. #5
    Join Date
    Jul 2006
    Posts
    36
    Quote Originally Posted by chazzy
    Actually you're supposed to have the capabilities of turning off the keys whenever you want.
    Yes, you're right. MySQL can do that, for example. But, by default, a defined key is enforced, until you make some change to the settings.
    HumanDoorway - free CAPTCHA service, no code needed

  6. #6
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    mysql has no "disable key"
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

  7. #7
    Join Date
    Jul 2006
    Posts
    36
    Quote Originally Posted by chazzy
    mysql has no "disable key"
    As far as I know - yes and no.

    The MySQL ALTER TABLE command has a DISABLE KEYS clause, but only for nonunique indexes. So, this is irrelevant for primary keys.
    HumanDoorway - free CAPTCHA service, no code needed

  8. #8
    Join Date
    Oct 2005
    Location
    California
    Posts
    603
    On an Insert statement, you can "initialise" an auto incrementing primary key by setting it to null.

  9. #9
    Join Date
    Aug 2005
    Location
    The Garden State
    Posts
    5,634
    Quote Originally Posted by thoughtcube
    As far as I know - yes and no.

    The MySQL ALTER TABLE command has a DISABLE KEYS clause, but only for nonunique indexes. So, this is irrelevant for primary keys.
    The problem with that is that the constraint is supposed to be considered its own entity, entirely separate from the table. of course it only exists as long as the table exists, but its status shouldn't be controlled by the table in that way.

    So yes, you can disable a key by altering a table but you can't alter a key's status by itself.
    Acceptable Use | SQL Forum FAQ | celery is tasteless | twitter

    celery is tasteless - currently needing some UI time

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles