1、一般情况,链接表 dep_cate 表是可以不要的,否则添加商品信息时,必须先添加dep_cate 表,操作麻烦,不实用
2、由外键能保证数据的一致性,至于前台如何避免错误数据,可以用选择框来选择,主要在前端实现。
3、思路应该没问题的 ,链接表 dep_cate 表到底要不要看需求的要求
2、由外键能保证数据的一致性,至于前台如何避免错误数据,可以用选择框来选择,主要在前端实现。
3、思路应该没问题的 ,链接表 dep_cate 表到底要不要看需求的要求
两个下拉框
譬如选择商品大类的某一项后,自动更新商品品牌的下拉内容(dep_cate是为了添加product的方便,过滤数据)
选择商品品牌的某一项后,也一样自动更新商品大类的下拉内容当然,也可以不要这张表,要添加的时候,就是所有商品大类选一个,所有商品品牌选一个
create trigger ttt on product
for insert
as
declare @intdepid int
select @intdepid=depId from department
declare @intcateid int
select @intcateid=cateId from categoryif exists(select 1 from department where depId=@intdepid)
begin
if exists(select 1 from category where cateId=@intcateid )
begin
if not exists(select 1 from dep_cate where depId=@intdepid and cateId=@intcateid )
begin
rollback
print ‘对应关系不存在'
end
end
else
begin
rollback
print 'cateId 不存在'
end
end
else
begin
rollback
print 'depId 不存在'
end