The function of go in SQL Server


No nonsense, please see the details below.

use db_CSharp
 select *,
 Remark = case 
 When grade > = 90 then 'excellent results'
 When grade < 90 and grade > = 80 then 'good grades'
 When grade < 80 and grade > = 70 then 'pass grade'
 Else 'fail'
 from tb_Grade

If you just execute a statement, is it the same with go

If multiple statements are separated by go, it is not the same

Each statement separated by go is a separate transaction. The failure of one statement will not affect the execution of other statements.

For example:

First, execute the statements below at the same time

select * from sysobjects where id=a
select getdate()

You will find that an error is reported and no result set is displayed

And you do it again

select * from sysobjects where id=a
select getdate()

You will find that the result set contains the result of select getdate() although the error is also reported.

PS: usage of go in SQL Server

Signaling Microsoft? SQL Server ™ Utility the end of a batch of transact SQL statements.
Go is not a transact SQL statement; it is a command recognized by OSQL and ISQL utilities and SQL Server Query Analyzer.

If your SQL is too long, you need to write go, or there are some statements, which can only be operated by the first sentence. Before that, you have to write go. Go means to process statements in batches. If you add this go, you will execute the code of go line, and then execute the next code

In cases like this, go is used to process data in batches

use master

if exists (select * from sysdatabases where name = 'kejianDB')
drop database kejianDB

create database kejianDB

use kejianDB

--(industry table)
create table Trade
tra_ Id int primary key identity (1,1) not null, -- industry ID (primary key, self growth)
tra_ Name varchar (50) not null -- industry name

The above is the whole description of this article, I hope you like it.

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]