What is the use of GO in SQL Server Management Studio & Transact SQL?

What is the use of GO in SQL Server Management Studio & Transact SQL?

SQL Server Management Studio always inserts a GO command when I create a query using the right click "Script As" menu. Why? What does GO actually do?

 

回答1

It is a batch terminator, you can however change it to whatever you want

What is the use of GO in SQL Server Management Studio & Transact SQL?

 

 

回答2

Just to add to the existing answers, when you are creating views you must separate these commands into batches using go, otherwise you will get the error ‘CREATE VIEW‘ must be the only statement in the batch. So, for example, you won‘t be able to execute the following sql script without go

create view MyView1 as
select Id,Name from table1
go
create view MyView2 as
select Id,Name from table1
go

select * from MyView1
select * from MyView2

 

What is the use of GO in SQL Server Management Studio & Transact SQL?

上一篇:MSSQL 发布订阅,实现读写分离 SQL Server


下一篇:在windows 10 bash里编写脚本