Friday, July 24, 2009

How to add a primary key to a table with existing data

The columns in the PK must be unique and NOT NULL. You may need to ensure these columns have unique data in them prior to setting the primary key. If the data is unique, the following statement (example) will work:

ALTER TABLE [dbo].[FactLocateOrdersSKUAggYear]
add primary key clustered (
[dw_order_year_key] ASC,
[dw_brand_id] ASC,
[dw_product_id] ASC
)

No comments:

Post a Comment