17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

So, let’s try a quick query direct from the command line. Again, remember that this is meant to be run<br />

from the Windows command prompt (don’t use the Management Console):<br />

<strong>SQL</strong>CMD -Usa -Pmypass -Q “SELECT * FROM AdventureWorks<strong>2008</strong>.Production.Location”<br />

The –P is the flag that indicates the password. If your server is configured with something other than a<br />

blank password (and it should be!), then you’ll need to provide that password immediately following the<br />

–P with no space in between. If you are using Windows authentication instead of <strong>SQL</strong> <strong>Server</strong> authentication,<br />

then substitute a -E and nothing else in the place of both the –U and –P parameters (remove<br />

both, but replace with just one –E).<br />

If you run this from a command prompt, you should get something like:<br />

C:\><strong>SQL</strong>CMD -E -Q “SELECT * FROM AdventureWorks<strong>2008</strong>.Production.Location”<br />

LocationID Name CostRate Avail<br />

ability ModifiedDate<br />

---------- -------------------------------------------------- ------------ -----<br />

------- -----------------------<br />

1 Tool Crib 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

2 Sheet Metal Racks 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

3 Paint Shop 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

4 Paint Storage 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

5 Metal Storage 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

6 Miscellaneous Storage 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

7 Finished Goods Storage 0.0000<br />

.00 1998-06-01 00:00:00.000<br />

10 Frame Forming 22.5000<br />

96.00 1998-06-01 00:00:00.000<br />

20 Frame Welding 25.0000<br />

108.00 1998-06-01 00:00:00.000<br />

30 Debur and Polish 14.5000<br />

120.00 1998-06-01 00:00:00.000<br />

40 Paint 15.7500<br />

120.00 1998-06-01 00:00:00.000<br />

45 Specialized Paint 18.0000<br />

80.00 1998-06-01 00:00:00.000<br />

50 Subassembly 12.2500<br />

120.00 1998-06-01 00:00:00.000<br />

60 Final Assembly 12.2500<br />

120.00 1998-06-01 00:00:00.000<br />

(14 rows affected)<br />

C:\><br />

Now, let’s create a quick text file to see how it works when including a file. At the command prompt,<br />

type the following:<br />

C:\>copy con testsql.sql<br />

Chapter 11: Writing Scripts and Batches<br />

341

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!