pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

當(dāng) ColumnId 相同時(shí),COLUMNS_UPDATED() 返回不同的值

COLUMNS_UPDATED() return different values when ColumnId is the same(當(dāng) ColumnId 相同時(shí),COLUMNS_UPDATED() 返回不同的值)
本文介紹了當(dāng) ColumnId 相同時(shí),COLUMNS_UPDATED() 返回不同的值的處理方法,對(duì)大家解決問(wèn)題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)吧!

問(wèn)題描述

我閱讀了關(guān)于 COLUMNS_UPDATED() 的文章 在 msdn 上.

I read the article about COLUMNS_UPDATED() on msdn.

有例子.我從示例中減少了代碼.使用觸發(fā)器創(chuàng)建表:

There are example. I reduce code from example. Create table with trigger:

CREATE TABLE dbo.employeeData (
   emp_id int NOT NULL PRIMARY KEY,
   emp_bankAccountNumber char (10) NOT NULL,
   emp_salary int NOT NULL,
   emp_SSN char (11) NOT NULL,
   emp_lname nchar (32) NOT NULL,
   emp_fname nchar (32) NOT NULL,
   emp_manager int NOT NULL
   );
GO
CREATE TRIGGER dbo.updEmployeeData 
ON dbo.employeeData 
AFTER UPDATE AS
    print COLUMNS_UPDATED() 
    print COLUMNS_UPDATED() & 14
GO
INSERT INTO employeeData
VALUES ( 101, 'USA-987-01', 23000, 'R-M53550M', N'Mendel', N'Roland', 32);
GO

  1. 第一次更新

  1. First update

UPDATE dbo.employeeData
SET emp_salary = 51000
WHERE emp_id = 101;

觸發(fā)器返回 0x04 和 4 - 一切正常

Trigger returned 0x04 and 4 - everything OK

第二次更新

UPDATE dbo.employeeData
SET emp_bankAccountNumber = '133146A0', emp_SSN = 'R-M53550M'
WHERE emp_id = 101;

觸發(fā)器返回 0x0A 和 10 - 一切正常

Trigger returned 0x0A and 10 - everything OK

但是讓我們嘗試添加一些列

CREATE TABLE dbo.employeeData2 (
    emp_id int NOT NULL PRIMARY KEY,
    emp_bankAccountNumber char (10) NOT NULL,
    emp_salary int NOT NULL,
    emp_SSN char (11) NOT NULL,
    emp_lname nchar (32) NOT NULL,
    emp_fname nchar (32) NOT NULL,
    emp_manager int NOT NULL,
    trash1 int NULL,
    trash2 int NULL,
    trash3 int NULL,
    trash4 int NULL,
    trash5 int NULL,
    trash6 int NULL,
    trash7 int NULL,
    trash8 int NULL,
    trash9 int NULL,
    trash10 int NULL,
    trash11 int NULL,
    trash12 int NULL,
    trash13 int NULL,
    trash14 int NULL,
    trash15 int NULL,
    trash16 int NULL,
    trash17 int NULL,
    trash18 int NULL,
    trash19 int NULL,
    trash20 int NULL,
    trash21 int NULL,
    trash22 int NULL,
    trash23 int NULL,
    trash24 int NULL,
    trash25 int NULL,
    trash26 int NULL,
    trash27 int NULL,
    trash28 int NULL,
    trash29 int NULL,
    trash30 int NULL,
    trash31 int NULL
   );
GO

CREATE TRIGGER dbo.updEmployeeData2
ON dbo.employeeData2
AFTER UPDATE AS
   print COLUMNS_UPDATED() 
   print COLUMNS_UPDATED() & 14
GO
INSERT INTO employeeData2
(emp_id,emp_bankAccountNumber,emp_salary,emp_SSN,emp_lname,emp_fname,emp_manager)
VALUES ( 101, 'USA-987-01', 23000, 'R-M53550M', N'Mendel', N'Roland', 32);
GO

現(xiàn)在更新時(shí)返回false

Now it return false when update

UPDATE dbo.employeeData2
SET emp_salary = 51000
WHERE emp_id = 101;
-- return 0x0400000000
-- return 0

UPDATE dbo.employeeData2
SET emp_bankAccountNumber = '133146A0', emp_SSN = 'R-M53550M'
WHERE emp_id = 101;
-- return 0x0A00000000
-- return 0

問(wèn)題:為什么 0x04 變成了 0x0400000000 而 0x0A 變成了 0x0A00000000 ?兩個(gè)表中的 ColumnId 相同.

推薦答案

嗯,msdn 對(duì)這個(gè)不是很清楚,但是有一個(gè)聲明,在你鏈接到的文檔中,你可以看到你必須當(dāng)您的表格中的列超過(guò) 8 列時(shí),可以采用另一種方式.

Well, msdn is not really clear on this one, but there's a statement, in the doc you're linking to, where you can see that you have to work another way when you have more than 8 columns in your table.

事實(shí)上,當(dāng)您有超過(guò) 8 列時(shí),您需要使用子字符串,即使您只處理前 8 列!

The fact is that you need to use substring when you have more than 8 column, even if you're working only on the first 8 columns !

如此處所述,同樣(給出的示例代碼與在 msdn)

as stated here, also (the sample code given is the same as in msdn)

但是,如果列數(shù)超過(guò)八列,則 COLUMNS_UPDATED()函數(shù)按從左到右的順序返回字節(jié),最少的最左邊的有效字節(jié).最左邊的字節(jié)將包含關(guān)于第 1 列到第 8 列的信息,第二個(gè)字節(jié)將包含有關(guān)第 9 列到第 16 列的信息,依此類推.如果有九個(gè)表中的列,并且您想檢查列 2、3 或 4 是否有已更新,使用的正確位掩碼是 0x0E00(十進(jìn)制 3584).

However, if there are more than eight columns, the COLUMNS_UPDATED() function returns the bytes in order from left to right, with the least significant byte being the leftmost. The leftmost byte will contain information about columns 1 through 8, the second byte will contain information about columns 9 through 16, and so on. If there were nine columns in the table and you want to check if columns 2, 3, or 4 have been updated, the correct bitmask to use is 0x0E00 (decimal 3584).

由于按位運(yùn)算符僅適用于 32 位整數(shù),因此您可能有難以檢查超過(guò) 32 列的表格.正確的位掩碼,用于檢查第 3、5 和 9 列在有 16 列時(shí)是否已更改列或更少是 0x1401(十進(jìn)制 5121).正確的位掩碼是0x140100 如果有 24 列或更少,0x14010000 如果有 32 列或少,等等.

Since the bitwise operator only works on 32-bit integers, you may have difficulty checking a table with more than 32 columns. The correct bitmask to check if columns 3, 5, and 9 have changed when there are 16 columns or less is 0x1401 (decimal 5121). The correct bitmask is 0x140100 if there are 24 columns or less, 0x14010000 if 32 columns or less, and so on.

因此,如果列數(shù)超過(guò)八列,則需要使用SUBSTRING 分別提取字節(jié)

Therefore, if there are more than eight columns, you will need to use SUBSTRING to extract the bytes separately

這篇關(guān)于當(dāng) ColumnId 相同時(shí),COLUMNS_UPDATED() 返回不同的值的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來(lái)源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問(wèn)題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個(gè)子標(biāo)記轉(zhuǎn)換為具有多個(gè)分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個(gè)表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計(jì)算值創(chuàng)建計(jì)算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對(duì)?) - IT屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(hào)(問(wèn)題和答案的組合))
主站蜘蛛池模板: 环比机械| 超声波破碎仪-均质乳化机(供应杭州,上海,北京,广州,深圳,成都等地)-上海沪析实业有限公司 | 砂尘试验箱_淋雨试验房_冰水冲击试验箱_IPX9K淋雨试验箱_广州岳信试验设备有限公司 | 电子巡更系统-巡检管理系统-智能巡检【金万码】 | PVC快速门-硬质快速门-洁净室快速门品牌厂家-苏州西朗门业 | 膜结构_ETFE膜结构_膜结构厂家_膜结构设计-深圳市烨兴智能空间技术有限公司 | 【黄页88网】-B2B电子商务平台,b2b平台免费发布信息网 | 欧版反击式破碎机-欧版反击破-矿山石料破碎生产线-青州奥凯诺机械 | 沈阳庭院景观设计_私家花园_别墅庭院设计_阳台楼顶花园设计施工公司-【沈阳现代时园艺景观工程有限公司】 | 湖南自考_湖南自学考试| 高效节能电机_伺服主轴电机_铜转子电机_交流感应伺服电机_图片_型号_江苏智马科技有限公司 | 实验室pH计|电导率仪|溶解氧测定仪|离子浓度计|多参数水质分析仪|pH电极-上海般特仪器有限公司 | 山东集装箱活动房|济南集装箱活动房-济南利森集装箱有限公司 | 喷码机,激光喷码打码机,鸡蛋打码机,手持打码机,自动喷码机,一物一码防伪溯源-恒欣瑞达有限公司 | 代理记账_免费注册公司_营业执照代办_资质代办-【乐财汇】 | 科研ELISA试剂盒,酶联免疫检测试剂盒,昆虫_植物ELISA酶免试剂盒-上海仁捷生物科技有限公司 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | 澳门精准正版免费大全,2025新澳门全年免费,新澳天天开奖免费资料大全最新,新澳2025今晚开奖资料,新澳马今天最快最新图库-首页-东莞市傲马网络科技有限公司 | 厂房出租_厂房出售_产业园区招商_工业地产 - 中工招商网 | 浙江自考_浙江自学考试网| 伺服电机_直流伺服_交流伺服_DD马达_拓达官方网站 | 密度电子天平-内校-外校电子天平-沈阳龙腾电子有限公司 | 铸钢件厂家-铸钢齿轮-减速机厂家-淄博凯振机械有限公司 | 电缆桥架生产厂家_槽式/梯式_热镀锌线槽_广东东莞雷正电气 | 膏剂灌装旋盖机-眼药水灌装生产线-西林瓶粉剂分装机-南通博琅机械科技 | 旋振筛|圆形摇摆筛|直线振动筛|滚筒筛|压榨机|河南天众机械设备有限公司 | 楼承板设备-楼承板成型机-免浇筑楼承板机器厂家-捡来 | 球盟会·(中国)官方网站| 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 交通气象站_能见度检测仪_路面状况监测站- 天合环境科技 | 生产加气砖设备厂家很多,杜甫机械加气砖设备价格公道 | 杭州网络公司_百度SEO优化-外贸网络推广_抖音小程序开发-杭州乐软科技有限公司 | 宏源科技-房地产售楼系统|线上开盘系统|售楼管理系统|线上开盘软件 | 菲希尔X射线测厚仪-菲希尔库伦法测厚仪-无锡骏展仪器有限责任公司 | 【灵硕展览集团】展台展会设计_展览会展台搭建_展览展示设计一站式服务公司 | 空气净化器租赁,空气净化器出租,全国直租_奥司汀净化器租赁 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 杭州实验室尾气处理_实验台_实验室家具_杭州秋叶实验设备有限公司 | 体感VRAR全息沉浸式3D投影多媒体展厅展会游戏互动-万展互动 | 工业淬火油烟净化器,北京油烟净化器厂家,热处理油烟净化器-北京众鑫百科 | 实验室隔膜泵-无油防腐蚀隔膜泵-耐腐蚀隔膜真空泵-杭州景程仪器 电杆荷载挠度测试仪-电杆荷载位移-管桩测试仪-北京绿野创能机电设备有限公司 |