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?
Thanksvivek...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..
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|||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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment