在 SQL Server 中,假设有这样的表,下面的过程将起作用:
CREATE TABLE MyBigTable(
ID INT NOT NULL PRIMARY KEY,
COLUMNA VARCHAR(100) NOT NULL,
COLUMNB VARCHAR(100) NOT NULL
)
GO
CREATE PROCEDURE UpdateMyBigTable(@ID INT, @ColumnAValue VARCHAR(100)=NULL, @ColumnBValue VARCHAR(100)=NULL)
AS BEGIN
UPDATE MyBigTable
SET COLUMNA = CASE WHEN @ColumnAValue IS NULL THEN COLUMNA ELSE @ColumnAValue END,
COLUMNB = CASE WHEN @ColumnBValue IS NULL THEN COLUMNB ELSE @ColumnBValue END
WHERE ID = @ID
AND ((COLUMNA <> @ColumnAValue AND @ColumnAValue IS NOT NULL) OR (COLUMNB <> @ColumnBValue AND @ColumnBValue IS NOT NULL));
END
GO
但是,这实际上并没有枚举您所询问的字段。如果不进入动态 SQL,这在 SQL Server 中是很难做到的。