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

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

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

問題描述

我閱讀了關(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)在更新時返回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 對這個不是很清楚,但是有一個聲明,在你鏈接到的文檔中,你可以看到你必須當(dāng)您的表格中的列超過 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.

事實上,當(dāng)您有超過 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)

但是,如果列數(shù)超過八列,則 COLUMNS_UPDATED()函數(shù)按從左到右的順序返回字節(jié),最少的最左邊的有效字節(jié).最左邊的字節(jié)將包含關(guān)于第 1 列到第 8 列的信息,第二個字節(jié)將包含有關(guān)第 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 位整數(shù),因此您可能有難以檢查超過 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.

因此,如果列數(shù)超過八列,則需要使用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 相同時,COLUMNS_UPDATED() 返回不同的值的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標(biāo)記轉(zhuǎn)換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創(chuàng)建視圖?)
Create calculated value based on calculated value inside previous row(根據(jù)前一行內(nèi)的計算值創(chuàng)建計算值)
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屋-程序員軟件開發(fā)技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉(zhuǎn)換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 久久精品国产久精国产 | 精品一二区 | 嫩草视频在线免费观看 | 玖玖视频网 | 黄网站免费在线观看 | 欧美专区在线视频 | 蜜臀久久99精品久久久久野外 | av大片| 狠狠的干| 九九综合九九 | 国产精品午夜电影 | 久久久www成人免费精品 | 91亚洲国产 | 欧美性video 精品亚洲一区二区 | 国产aⅴ精品| 一级毛片视频免费观看 | 欧美在线观看一区 | 国产专区在线 | 黄a免费看| 日韩影院在线观看 | 中文字幕精品一区二区三区在线 | 欧美寡妇偷汉性猛交 | 拍拍无遮挡人做人爱视频免费观看 | 天天干亚洲 | 国产高清一二三区 | 欧美中文字幕 | 亚洲一二三区不卡 | 男女羞羞视频在线免费观看 | 国产欧美一区二区三区在线播放 | 欧美日韩久久 | 亚洲网站在线观看 | 久久久久久久久91 | 欧美亚洲高清 | 亚洲综合一区二区三区 | 亚洲精选久久 | 日日夜夜精品 | 久久国产精99精产国高潮 | 91社区在线观看播放 | 视频在线一区二区 | 欧美日韩不卡合集视频 | 日韩中字幕 |