有关改进更新查询的建议

时间:2019-06-28 15:44:52

标签: default-value actionresult

我创建了以下功能正常的脚本。 即使这样,我也希望得到任何改进建议。 预先谢谢你。

USE [MyDb]
GO

BEGIN       
DECLARE
    @OldValue TABLE (SettingKey NVARCHAR(128), SettingValue NVARCHAR(128))

    INSERT INTO @OldValue 
        SELECT SettingKey, SettingValue FROM cSettingData WHERE SettingKey = 'WebAppsHostname' OR SettingKey = 'Hostname'

    BEGIN
        SET NOCOUNT ON;
            DECLARE
                @ComputerName NVARCHAR(128)
            SET 
                @ComputerName = HOST_NAME ()
                --@ComputerName = 'MyServerName'

            UPDATE cSettingData 
                SET SettingValue = @ComputerName
                WHERE SettingKey = 'WebAppsHostname'
                    OR SettingKey = 'Hostname'
                    AND SettingDefFK = 'ServiceConfiguration' 
    END

DECLARE
    @NewValue TABLE (SettingKey NVARCHAR(128), SettingValue NVARCHAR(128))

INSERT INTO @NewValue 
        SELECT SettingKey, SettingValue FROM cSettingData WHERE SettingKey = 'WebAppsHostname' OR SettingKey = 'Hostname'

SELECT O.SettingKey as RowName, O.SettingValue AS OldValue, N.SettingValue AS NewValue
    FROM @OldValue as O
    INNER JOIN @NewValue as N
        ON O.SettingKey = N.SettingKey
    WHERE O.SettingKey = 'WebAppsHostname' OR O.SettingKey = 'Hostname'

END

结果截图; https://imgur.com/a/XtKeGGc

0 个答案:

没有答案