久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

當 ColumnId 相同時,COLUMNS_UPDATED() 返回不同的值

COLUMNS_UPDATED() return different values when ColumnId is the same(當 ColumnId 相同時,COLUMNS_UPDATED() 返回不同的值)
本文介紹了當 ColumnId 相同時,COLUMNS_UPDATED() 返回不同的值的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

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

I read the article about COLUMNS_UPDATED() on msdn.

有例子.我從示例中減少了代碼.使用觸發器創建表:

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;

觸發器返回 0x04 和 4 - 一切正常

Trigger returned 0x04 and 4 - everything OK

第二次更新

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

觸發器返回 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

現在更新時返回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

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

推薦答案

嗯,msdn 對這個不是很清楚,但是有一個聲明,在你鏈接到的文檔中,你可以看到你必須當您的表格中的列超過 8 列時,可以采用另一種方式.

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.

事實上,當您有超過 8 列時,您需要使用子字符串,即使您只處理前 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)

但是,如果列數超過八列,則 COLUMNS_UPDATED()函數按從左到右的順序返回字節,最少的最左邊的有效字節.最左邊的字節將包含關于第 1 列到第 8 列的信息,第二個字節將包含有關第 9 列到第 16 列的信息,依此類推.如果有九個表中的列,并且您想檢查列 2、3 或 4 是否有已更新,使用的正確位掩碼是 0x0E00(十進制 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).

由于按位運算符僅適用于 32 位整數,因此您可能有難以檢查超過 32 列的表格.正確的位掩碼,用于檢查第 3、5 和 9 列在有 16 列時是否已更改列或更少是 0x1401(十進制 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.

因此,如果列數超過八列,則需要使用SUBSTRING 分別提取字節

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

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

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

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
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?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 日本精品在线一区 | 欧美天堂一区 | 中文字幕亚洲专区 | 国产电影一区二区 | 亚洲国产aⅴ精品 | 欧美日日日日bbbbb视频 | 黑人精品 | 伊人网在线播放 | 国产成人麻豆免费观看 | 久久久久99 | 伊人超碰在线 | 久久综合伊人一区二区三 | 91精品国产91久久久久久 | 一区二区在线免费播放 | 午夜tv免费观看 | 国产精品成人在线 | 日本在线免费视频 | 日本电影免费完整观看 | 正在播放国产精品 | 久久久久国产一区二区 | 精品99久久久久久 | 免费v片在线观看 | 精品亚洲永久免费精品 | 国产日韩欧美精品 | 国产精品久久久久久久久久免费看 | 亚洲一区二区av | 免费一级黄色 | 色精品| 久久久久久国产精品 | 欧美亚洲国产一区二区三区 | 国产美女黄色片 | 请别相信他免费喜剧电影在线观看 | 亚洲精品在线免费 | 国产综合在线视频 | www在线视频 | 一区二区伦理电影 | 欧美日韩亚洲系列 | 亚洲精品成人免费 | av一区在线观看 | 欧美一区二区在线观看 | 伊人精品国产 |