具體不廢話了,請看下文詳解。
1 2 3 4 5 6 7 8 9 10 | use db_CSharp go ? select *, ? 備注= case ? when Grade>=90 then '成績優秀' ? when Grade<90 and Grade>=80 then '成績良好' ? when Grade<80 and Grade>=70 then '成績及格' ? else '不及格' ? end ? from tb_Grade |
如果只是執行一條語句,有沒有GO都一樣
如果多條語句之間用GO分隔開就不一樣了
每個被GO分隔的語句都是一個單獨的事務,一個語句執行失敗不會影響其它語句執行。
例如:
首先同時執行下邊的語句
1 2 | select * from sysobjects where id=a select getdate() |
你會發現會報錯,并且不會顯示任何結果集
而你再執行
1 2 3 4 | select * from sysobjects where id=a go select getdate() go |
你會發現盡管同樣會報錯,但結果集中包含select getdate()的結果。
ps:SQL SERVER 中 GO 的用法
用信號通知 Microsoft? SQL Server? 實用工具一批 Transact-SQL 語句的結束。
GO 不是 Transact-SQL 語句;而是可為 osql 和 isql 實用工具及 SQL Server 查詢分析器識別的命令。
如果你的SQL過長的時候,就要寫GO,或者有一些語句,它只能是第一句操作的,在之前你也得寫 GO ,GO的意思 是 分批處理語句 有加這個 GO ,就執行GO 行的代碼,執行后再執行接下來的代碼……
像這樣的情況下就要用到GO ,分批處理數據……
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | use master go if exists ( select * from sysdatabases where name = 'kejianDB' ) drop database kejianDB go create database kejianDB go use kejianDB go --(行業表) create table Trade ( tra_Id int primary key identity(1,1) not null , --行業ID (主鍵、自增長) tra_Name varchar (50) not null --行業名稱 ) go |