Results 1 to 5 of 5

Thread: primary keys

  1. #1
    Join Date
    Mar 2004
    Posts
    64

    Question Unanswered: primary keys

    I have a question about primary key,
    I would like to create a database by importing from an Excel sheet, but the data is not good enough, now we have some empty and duplicated fields and I want to create a composite primary key on the table so that later that no duplicates records and blank field will happen.
    But for some of the previous records we cannot find those information for the blank fields, but we still want to keep them in the table. Is there any way that I can create the PK to inforce referencial integrity only for future entered recods but still keep the old records the same as it was.

    Thanks

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    No, not at the table level. Either a field is null or not null, you can't pick when to enforce a table-level constraint on a row-by-row basis.

    You'll probably have to do the validation during your import process...
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    Yeah - a primary key cannot logically (in all senses of the word) contain nulls.

    You can, however, define a unique composite index and specify that Nulls are to be ignored. Any key containing a Null won't be added to the index. Closest you can get unless you get rid of the offending records.

    Remember:
    Quote Originally Posted by Codd
    The values in a row are dependant on the key, the whole key, and nothing but the key, so help me Codd
    without the key you don't have a record
    Testimonial:
    pootle flump
    ur codings are working excelent.

  4. #4
    Join Date
    Feb 2004
    Location
    One Flump in One Place
    Posts
    14,912
    A brief flicker of a thought - SQL Server has a NO CHECK option when creating an index programmatically (all previously entered data is not checked against the constraint). JET might have the same. I would doubt it... and even if it did I am not sure that it would allow you to apply this when creating a primary key.
    Testimonial:
    pootle flump
    ur codings are working excelent.

  5. #5
    Join Date
    Mar 2004
    Posts
    64
    Thanks all. It's helpful

Posting Permissions

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