Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2004
    Location
    Montreal, Canada
    Posts
    151

    Unanswered: inserting nulls into a primary key

    The Question is ...Is there a way or work around to inserting a blank values into a primary field PLZ HELP.

  2. #2
    Join Date
    Sep 2003
    Location
    Dallas, Texas
    Posts
    311

    Re: inserting nulls into a primary key

    A blank is ok but null is NOT allowed. See BOL under the subject of 'Creating and Modifying PRIMARY KEY Constraints'

  3. #3
    Join Date
    Jan 2004
    Posts
    12
    One would think not. Primary keys are unique by definition. If you need to be inserting blank values into a primary key that field/column probably isn't your primary key.

  4. #4
    Join Date
    Jan 2004
    Location
    Montreal, Canada
    Posts
    151
    thank ..but could you show me in code how to do this.

  5. #5
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Hey, but he would only be able to put in one....

    Where did I put that thread...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  6. #6
    Join Date
    Jan 2004
    Location
    Montreal, Canada
    Posts
    151
    the thing is that my warehouse requires this as this is a modification i only need to know how to insert that blank spot in that primary key any help would be very much aprreciated

  7. #7
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Here it is...


    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=31801


    Can you post the DDL of your table?

    And you can insert a blank in to a pk...but only once

    If it's a composite (col, col2) Then only once for the unique occurance of col1, and so on...

    Maybe if you explain why you need to do this...
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  8. #8
    Join Date
    Jun 2003
    Location
    Ohio
    Posts
    12,592
    Provided Answers: 1
    Primary keys aren't even ALLOWED to accept nulls. The closest you could come would be using a zero-lengths string on a character-based primary key, but again you would only be able to insert one record.

    You can't do what you are trying to do, but I suspect that the problem lies in your database design than in SQL Server's limitations.
    If it's not practically useful, then it's practically useless.

    blindman
    www.chess.com: "sqlblindman"
    www.LobsterShot.blogspot.com

Posting Permissions

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