创建外键的一个简单例子

有两个数据库表:

Product表,表中字段如下:

ProductID

Name

Price

Size

ProductCategoryID

 

ProductCategory表,表中字段如下:

ProductCategoryID

Name

 

现在想在Product表中为ProductCategoryID创建外键,方法如下:

alter table Product

add constraint Product_ProductCategory_FK

foreign key(ProductCategoryID) references

ProductCategory(ProductCategoryID)

on cascade delete

on cascade update

这样就为Product表创建了一个外键约束。

你可能感兴趣的:(C#.NET编程)