Sql server 2005 SQLServer2005中的SQL建模(一对多)
我有一个Sql server 2005 SQLServer2005中的SQL建模(一对多),sql-server-2005,database-design,Sql Server 2005,Database Design,我有一个产品表: ProdId(PK) Prod1 Prod2 Prod3 Prod4 Certification(PK): Cert1 Cert2 Cert3 和认证表: ProdId(PK) Prod1 Prod2 Prod3 Prod4 Certification(PK): Cert1 Cert2 Cert3 我需要对ProdwithCert关系(伪表)建模如下: ProdwithCertId(PK) ProdwithCert Prod
产品
表:
ProdId(PK)
Prod1
Prod2
Prod3
Prod4
Certification(PK):
Cert1
Cert2
Cert3
和认证
表:
ProdId(PK)
Prod1
Prod2
Prod3
Prod4
Certification(PK):
Cert1
Cert2
Cert3
我需要对ProdwithCert
关系(伪表)建模如下:
ProdwithCertId(PK) ProdwithCert
ProdwithCert1 "Prod1 with Cert1"
ProdwithCert2 "Prod1 with Cert1, Cert2"
ProdwithCert3 "Prod1 with Cert1, Cert2, Cert3"
ProdwithCert4 "Prod2 with Cert1, Cert2"
ProdwithCert5 "Prod2 with Cert1, Cert2, Cert3"
以下是限制条件:
ProdwithCert6-“Prod2 with Cert1、Cert2、Cert3”是不允许的
产品
至少有一个认证
ProdwithCert
关系
感谢第一个要求可以通过
ProdwithCert
表来满足,该表在(ProductId,CertId)
上具有主键(或唯一索引)
第二个要求不能使用键约束或检查约束强制执行。我唯一能想到的就是通过存储过程传递所有修改。该过程可以在一个事务中添加具有证书的产品