Flylib.com

Books Software

 
 
 

Using SQLCmd

Using SQLCmd

SQLCmd is a command line tool that allows you to enter T-SQL sentences or script files by connecting to the SQL Server instance using OLE DB. SQLCmd is the replacement for the previous osql command.

Working with the SQLCmd Utility

To start the SQLCmd utility, you should launch SQLCmd from the command line. You can use the default SQL Server instance or connect to a named SQL Server instance.

Connecting to a Default SQL Server Instance
  1. From the Start menu, click Run. In the Open textbox, type cmd and click OK.

  2. In the command prompt, type sqlcmd and press Enter.

  3. You will enter the SQLCmd shell and observe a 1> prompt.

  4. Type Select name from sys.databases and press Enter.

  5. Type Go and press Enter. The result will be displayed.

  6. Type Exit and press Enter to quit SQLCmd.

If you want to connect to a named instance, you should use the S input parameter and specify the instance name in the Server\Instance format. You can view all input parameters by executing SQLCmd /?, as shown in Figure 3-20.

image from book
Figure 3-20: SQLCmd input parameters.

Executing Script Files

You can use SQLCmd to execute script files from the command line, which allows you to schedule scripts outside the SQL Server instance.

Executing the DTA.sql Script by Using the SQLCmd Utility
  1. From the Start menu, click Run.

  2. In the Open textbox, type cmd and click OK.

  3. In the command prompt, type sqlcmd i < path >\Ch03\SQLCmd.sql (replace <path> with the path in which you installed the sample files).

  4. Press Enter. A list of product names is displayed.

Conclusion

You have learned how to configure your SQL Server instance and the security features in SQL Server 2005 by using the new SQL Server Surface Area Configuration tool. You have learned to use the new SQL Server Management Studio and Database Engine Tuning Advisor, as well as the enhanced SQL Server Profiler.

Chapter 3 Quick Reference

To

Do This

Learn about SQL Server 2005 features and search for help

Use SQL Server Books Online.

Configure a SQL Server 2005 instance

Use the SQL Server Configuration Manager tool.

Manage databases and run queries

Use the new SQL Server Management Studio or the SQLCmd tool.

Tune a SQL Server instance

Use the new Database Engine Tuning Advisor.

Analyze your SQL Server query performance and server use

Use SQL Server Profiler and Performance Monitor.

Part II: How to Create a Microsoft SQL Server 2005 Database

Chapter List

Chapter 4: Gathering and Understanding Business Requirements before Creating Database Objects
Chapter 5: Designing a Database to Solve Business Needs

Chapter 4: Gathering and Understanding Business Requirements before Creating Database Objects

Overview

After completing this chapter, you will be able to:

  • Gather requirements from the database perspective

  • Understand business data and its lifetime

  • Pinpoint operating requirements such as performance, scalability, and security

  • Estimate capacity planning

In previous lessons, you learned the basics of Microsoft SQL Server 2005: how it may help you, how to install it, and what tools it offers. We will now shift the focus from SQL Server 2005 to your application and explore the way you should capture business requirements to build a solid foundation for your design.

Programmers and project managers frequently underestimate how critical the gathering and comprehension of business requirements are in the software development processwith devastating effects. Industry studies estimate that more than 35% and up to 50% of project failures are related to lack of user input as well as incomplete or changing requirements. The Standish Group International Inc., in their Chaos Report and Extreme Chaos Reports, estimated that only 29% of all projects succeeded (delivered on time, on budget, with required features and functions). If you apply the concepts learned in this lesson, you will avoid much of that risk and increase your development effectiveness.