本文介紹了SQL 腳本不工作,但個別查詢工作的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在使用以下腳本向我的表中添加一列.當我在查詢窗口中點擊 F5 時,它會在第二次更新查詢中出現 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
但是當我一一運行這些查詢時,它沒有給出錯誤.誰能告訴我這個腳本有什么問題?
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
.這樣,每條語句的結果將在運行下一條之前提交(每條語句將是一個單獨的事務).
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
這篇關于SQL 腳本不工作,但個別查詢工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!