We already have 2 tables:
Product: ProductID - int-primary key-indexed Name - nvarchar(15) testProductAttribute testProductAttributeID- int-primary key-indexed ProductID-int
Now we would like to create a foreign key relationship between these 2 tables. Key benefit is that, if there is a attribute data for a product in testProductAttribute table, we will not be able delete the record from Product table. (Off-course we can change this option)
ALTER TABLE testProductAttribute ADD FOREIGN KEY (ProductID) REFERENCES Product(ProductID)
First of all, we want to delete the previously created Foreign Key:
ALTER TABLE testProductAttribute DROP CONSTRAINT FK__testProdu__Produ__38996AB5
FK__testProdu__Produ__38996AB5 is the system generated name for our previous query which can be different and we can find the name from “Keys” folder of the testProductAttribute table.
Now please go through as follows: