Results 1 to 3 of 3

Thread: Checking for PK

  1. #1
    Join Date
    Sep 2003
    Posts
    176

    Unanswered: Checking for PK

    Hi,

    I want to assign a list columns to be the PK on a table. I don't know what this list of columns would be.How do I go about figuring that?

    Sample Data

    Col1...Col2...Col3..Col4
    1...........2.......A......X
    1...........2........B.....X
    1...........2.......A......Y



    As you can see Col1 & Col2 ONLY do not make up the PK. I need to include Col3 as well. My concern is I am not sure if I have a row like..
    1...........2.......A......X reapeated lower down the order. So how do I figure the PK out?

    Thanks

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    vivek...post your sample so we can cut and paste them...

    btw...you have a 4 composite pk you're looking for, based on what you're asking for..

    Code:
    USE Northwind
    GO
    
    CREATE TABLE myTable99(Col1 int, Col2 int, Col3 char(1), Col4 char(1)
    	, PRIMARY KEY (Col1, Col2, Col3, Col4))
    GO
    
    INSERT INTO myTable99(Col1,Col2,Col3,Col4)
    SELECT 1,2,'A','X' UNION ALL
    SELECT 1,2,'B','X' UNION ALL
    SELECT 1,2,'A','Y'
    GO
    
    --So Good So Far
    
    SELECT * FROM myTable99
    GO
    
    -- Oops...No Good
    
    INSERT INTO myTable99(Col1,Col2,Col3,Col4)
    SELECT 1,2,'A','X'
    
    DROP TABLE myTable99
    GO
    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.

  3. #3
    Join Date
    Sep 2003
    Posts
    176
    I figured the solution out. I find that my entire row serves as the primary key. So now I want to compare this with a similar table having the row as the PK. I am thinking on how do I go about this right now. Any ideas are welcome.

    Thanks.

Posting Permissions

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