Solved

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

Posted on 2007-11-26
6
226 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
ID: 20355847
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
ID: 20355865
0
 

Author Comment

by:iangregson1
ID: 20355875
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 

Author Comment

by:iangregson1
ID: 20357310
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
ID: 20357324
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
ID: 20357356
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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