以前用Sql Server只会对图形界面进行操作,现在发现自己的Sql语言功底是越来越差了,例如如何为两个表添加关联,让他们级联更新和级联 删除。 到晚上查了一下,发现可以用两种办法 触发器方式: create trigger trg_A on A for update,delete as begin if exists(select 1 from inserted) update B set Name=(select Name from inserted) where Name=(selec
用游标实现,我觉得绝对这种方法比较安全的。–首先定一个游标把需要用到的一些数据存放到游标中: 代码如下:declare CURSOR D_CURSOR_CUS_INFO IS select t3.id_ as id_, t3.owe_money_ as owe_money_, a.heatingArea as heating_area_ from T_CUS_OWE_MONEY_2 t2 left jo
代码如下:on delete cascade
当你更新或删除主键表时,那么外键表也会跟随一起更新或删除,需要在建表时设置级联属性
CREATE TABLE Countries(CountryId INT PRIMARY KEY) INSERT INTO Countries (CountryId) VALUES (1) INSERT INTO Countries (CountryId) VALUES (2) INSERT INTO Countries (CountryId) VALUES (3)