本文介紹了SQL 腳本不工作,但個別查詢工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在使用以下腳本向我的表中添加一列.當(dāng)我在查詢窗口中點(diǎn)擊 F5 時,它會在第二次更新查詢中出現(xiàn) fkRefTabNo
不存在的錯誤.
I am using the following script to add a column to my table. When I hit F5 in the query window it gives an error on the 2nd update query that fkRefTabNo
doesn't exist.
ALTER TABLE EPFieldSQLScripts
ADD fkRefTabNo int DEFAULT 1
update EPFieldSQLScripts
set fkRefTabNo = 1
where fkRefTabNo is null
ALTER TABLE EPFieldSQLScripts
ALTER COLUMN fkRefTabNo INTEGER NOT NULL
但是當(dāng)我一一運(yùn)行這些查詢時,它沒有給出錯誤.誰能告訴我這個腳本有什么問題?
But when I run these queries one by one, it doesn't give an error. Can anyone tell me what is wrong with this script?
推薦答案
在語句之間放置 GO
.這樣,每條語句的結(jié)果將在運(yùn)行下一條之前提交(每條語句將是一個單獨(dú)的事務(wù)).
Put GO
between statements. This way the result of each statement will be committed before running the next one (each statement will be a separate transaction).
ALTER TABLE EPFieldSQLScripts
ADD fkRefTabNo int DEFAULT 1
GO
update EPFieldSQLScripts
set fkRefTabNo = 1
where fkRefTabNo is null
GO
ALTER TABLE EPFieldSQLScripts
ALTER COLUMN fkRefTabNo INTEGER NOT NULL
這篇關(guān)于SQL 腳本不工作,但個別查詢工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!