-- 理论结合实际,完善一下 if OBJECT_ID('tab') is not null drop table tab; go create table tab (c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int, c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int); go create trigger trg_update_tab on tab for update as print columns_updated(); rollback tran; go insert into tab values(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16); go update tab set c1=0; /*0x0100 */ update tab set c2=0,c3=0,c4=0; /*0x0E00 */ update tab set c7=0,c8=0,c9=0; /*0xC001 */
则@i列受影响
c8 c7 c6 c5 c4 c3 c2 c1 c16 c15 c14 c13 c12 c11 c10 c9
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0检查 c2、c3、c4 对应的二进制数为 0000 1110 0000 0000 ,十六进制为 0xE00
columns_update() & 0xE00检查 c7、c8、c9 对应的二进制数为 1100 0000 0000 0001,十进制为 0xC001
columns_update() & 0xC001
猫大侠,顺序为什么是这样:c8 c7 c6 c5 c4 c3 c2 c1 c16 c15 c14 c13 c12 c11 c10 c9
10000000=8
1000000=7所以有 power(2,6)+power(2,7)+power(2,8)=448所以有 if(columus_updated()&448) >0
-- 理论结合实际,完善一下
if OBJECT_ID('tab') is not null
drop table tab;
go
create table tab
(c1 int,c2 int,c3 int,c4 int,c5 int,c6 int,c7 int,c8 int,
c9 int,c10 int,c11 int,c12 int,c13 int,c14 int,c15 int,c16 int);
go
create trigger trg_update_tab on tab
for update
as
print columns_updated();
rollback tran;
go
insert into tab values(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16);
go
update tab set c1=0;
/*0x0100 */
update tab set c2=0,c3=0,c4=0;
/*0x0E00 */
update tab set c7=0,c8=0,c9=0;
/*0xC001 */