在SQL Server中删除行,只有一列为零

时间:2019-08-07 13:08:50

标签: sql-server triggers calculated-columns

我在SQL Server 2012中有2个表的数据库。

表A

aid, (used), max_count

表B

bid, aid, x

表B中的bid是主键,而aid是表A的外键。

在表A中,aid是主键,并且used是计算列,其计数然后对表B中已使用的aid进行计数。

我要始终在表A中used <= max_count

如何控制表A上max_count不小于used的更新?

如何控制used不大于max_count的添加到表B?

1 个答案:

答案 0 :(得分:0)

此触发器可用于插入B并更新A。您可能还需要其他触发器来更新B。

#!/usr/bin/env python3
from random import *

Livros = ["Lucas", "Isaias"]


Lucas = ["Lucas1", "Lucas2"]
Isaias = ["Isaias1", "Isaias2"]

Lucas1 = {
    "1" : "Text1" ,
    "2" : "Text2" ,
    "3" : "Text3" ,
    "4" : "Text4"
}

Lucas2 = {
    "1" : "Text1" ,
    "2" : "Text2" ,
    "3" : "Text3" ,
    "4" : "Text4" 
}

Isaias1 = {
    "1" : "Text1" ,
    "2" : "Text2" ,
    "3" : "Text3" ,
    "4" : "Text4"
}


Isaias2 = {
    "1" : "Text1" ,
    "2" : "Text2" ,
    "3" : "Text3" ,
    "4" : "Text4"
}

x = choice(Livros)
print(x)

xx = choice(x)
print(xx)```