Solved

sql server management studio questions with regards to attaching and using GO?

Posted on 2007-11-26
6
223 Views
Last Modified: 2013-11-26
Hi there,

I have been using the sql server management studio (express) and i would like to know what the difference is of creating a db in the studio or creating in VS 2005... it appears that one is attached and the other isn't?

What are the pros and cons of the 2 different ways?

Also when i write queries etc in sqlcmd.. i use GO to execute the command/s ...but in SQL Management studio is there any point to GO?? As you click the EXECUTE button on the toolbar to execute the script which i assume executes ALL of the script not just the current line

If anybody can confirm anything i would be really grateful..

thansk
0
Comment
Question by:iangregson1
  • 4
6 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
Comment Utility
Hello iangregson1,
Management studio is the IDE for SQL
GO - indicates the end of a batch ,the variables declared above wont be available for the statements beneath tht 'GO'


Aneesh R
0
 
LVL 55

Expert Comment

by:Jaime Olivares
Comment Utility
0
 

Author Comment

by:iangregson1
Comment Utility
Hi thanks for the reply, but it is totally valid to do the following in SSMS

command
GO

command
GO
etc

it sqlcmd GO executes the statements.. but in SSMS when you click execute it seems that ALL statements are executed weather or not the GO is there??

0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:iangregson1
Comment Utility
Ermm maybe i didn't explain myself correctly, ok is SSMS .. if i put this into a query window .. i get 2 resultsets back... but i didn't use GO??  So what is the difference?  I just click the EXECUTE .. and all 3 commands are evaluated and run...

USE test;

SELECT * FROM dbo.Table_1 WHERE test='1';

SELECT * FROM dbo.Table_1 WHERE test='2';

0
 

Author Comment

by:iangregson1
Comment Utility
I even tried this... and the execute sure enough EXECUTES all commands.. with or without a GO

USE test;

SELECT * FROM dbo.Table_1 WHERE test='1';

SELECT * FROM dbo.Table_1 WHERE test='2';

GO


SELECT * FROM dbo.Table_1 WHERE test='4';
0
 

Author Comment

by:iangregson1
Comment Utility
Oh i think i found, can anyone confirm it for me..

If you make 4 statements into one batch like this --

statement1; statement2; statement3; statement4 GO

....and statement4 fails with an error, the affected objects are
restored to the way they were before statement1.   so if 4 FAILS then ALL fails!

If you make them 4 separate batches like this --

statement1 GO statement2 GO statement3 GO statement4 GO

.... and statement4 fails with an error, the objects are restored to
the way they were after statement 3.

So i presume a long script without using GO then  if something failed ... they would all get returned to how they were before??? Pretty much like putting a GO at the end of a script...??

Any advise really appreciated
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now