如何編寫我的SQL腳本以確保新列在創建後的後續行中可見。如何在SQL腳本中創建新列之後立即引用新列
這是我的SQL的一般形式:
BEGIN TRANSACTION
if (not exists(select 1 from THIS_TABLE))
BEGIN
ALTER TABLE THIS_TABLE add THIS_COLUMN int
END
COMMIT
BEGIN TRANSACTION
IF (NOT EXISTS (SELECT 1 FROM THIS_TABLE
WHERE THIS_COLUMN = 1))
BEGIN
UPDATE THIS_TABLE SET THIS_COLUMN = 1
END
COMMIT
這是我得到的錯誤:在此行
Invalid column name 'THIS_COLUMN'.
:
IF (NOT EXISTS (SELECT 1 FROM THIS_TABLE
WHERE THIS_COLUMN = 1))