[英]Adding a column to a table with a primary key
我正在嘗試將現有表(產品表)中的類別從類別替換為productCategoryID,這也是ProductCategory表中的主鍵。 到目前為止,我已經粘貼了進度,但是被卡住了。
alter table product
Add ProductCategoryID smallint
constraint PK_ProductCategory Primary Key (ProductCategoryID)
references ProductCategory(ProductCategoryID)
在此先感謝您的時間和幫助!
您必須首先添加一列。 然后,您可以向表中添加約束。 這些步驟不能同時執行。 而且,主鍵引用另一個表中的列的概念沒有任何意義。 那是一個外鍵。 我懷疑您想要這些東西。
alter table product
Add ProductCategoryID smallint
alter table product
add constraint FK_ProductCategory Foreign Key (ProductCategoryID)
references ProductCategory(ProductCategoryID)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.