您的位置:首页 > Web前端

Beginning ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(4)

2008-10-29 11:11 666 查看
The sqlcmd Command-Line Tool
sqlcmd命令行工具
SQL Server 2005 (and 2008) include a handy command-line tool named sqlcmd.exe that you can use to perform database tasks from a Windows command prompt. Compared to a management tool like SQL Server Management Studio, sqlcmd doesn’t offer many frills. It’s just a quick-and-dirty way to perform a database task. Often, sqlcmd is used in a batch file—for example, to create database tables as part of an automated setup process.
SQL Server 2005(及2008)包括一个方便的名为sqlcmd.exe的命令行工具,您可用于从Windows命令提示符执行数据库任务。相比像SQL Server Management Studio管理工具中,sqlcmd不提供许多调试。这只是一个快捷的方式来执行数据库任务。通常,SQLCMD使用一个批处理文件,例如,要创建数据库表的一部分自动安装过程。
The sqlcmd tool is installed as part of SQL Server 2005 (and 2008), and it’s found in a directory like c:/Program Files/Microsoft SQL Server/90/Tools/Binn. The easiest way to runsqlcmd is to launch the Visual Studio command prompt (open the Start menu and choosePrograms->Microsoft Visual Studio 2008->Visual Studio Tools->Visual Studio 2008 CommandPrompt). This opens a command window that has the SQL Server directory set in the path variable. As a result, you can use sqlcmd anywhere you want, without typing its full directorypath.
sqlcmd工具作为SQL Server 2005(2008)的一部分已经安装,在c:/Program Files/Microsoft SQL Server/90/Tools/Binn目录中可以找到。最简单运行的SQLCMD方式是启动Visual Studio命令提示符(打开开始菜单,并选择程序的MicrosofVisual Studio 2008-> Visual Studio工具->命令提示)。这将打开一个命令窗口,有SQL Server目录中确定的变量路径。因此,您可以在如何地方不用输入其全部目录使用sqlcmd。
When running sqlcmd, it’s up to you to supply the right parameters. To see all the possible parameters, type this command:
sqlcmd -?
当运行sqlcmd ,它由您来决定如何提供正确的参数。想看到所有可能的参数,输入这个命令: sqlcmd -?
Two commonly used sqlcmd parameters are –S (which specifies the location of your database server) and –i (which supplies a script file with SQL commands that you want to run). For example, the downloadable code samples include a file named InstPubs.sql that contains the commands you need to create the pubs database and fill it with sample data. If you’re using SQL Server Express, you can run the InstPubs.sql script using this command:
两种常用的sqlcmd参数是–S(指定你的数据库服务器的位置)和–i(它提供了你要运行的一个SQL命令的脚本文件)。例如,下载的代码样本包括一个名为InstPubs.sql的脚本,它包含了您需要建立pubs数据库,并填写样本数据的命令。如果您使用 SQL Server Express,可以运行脚本InstPubs.sql使用此命令:
sqlcmd -S localhost/SQLEXPRESS -i InstPubs.sql
If you’re using a full version of SQL Server on the local computer, you don’t need to supply the server name at all:
如果您使用的是在本地计算机上的完整版本的SQL Server,你不需要供应服务器名称:
sqlcmd -i InstPubs.sql
And if your database is on another computer, you need to supply that computer’s name with the –S parameter (or just run sqlcmd on that computer).
Figure 15-4 shows the feedback you’ll get when you run InstPubs.sql with sqlcmd.
如果您的数据库是在另一台计算机上,您需要提供该计算机的名称与- S参数(或只是在该计算机上运行sqlcmd)。 图15-4显示了当您使用sqlcmd运行InstPubs.sql反馈信息。


In this book, you’ll occasionally see instructions about using sqlcmd to perform some sort of database configuration. However, you can usually achieve the same result (with a bit more clicking) using the graphical interface in a tool like SQL Server Management Studio. For example, to install a database by running a SQL script, you simply need to start SQL Server Management Studio, open the SQL file (using the File->Open->File command), and then run it (using the Query->Execute command).
在这本书中,你会偶尔看到有关使用sqlcmd执行一些这类数据库配置。然而,使用图形界面的工具像SQL Server Management Studio通常可以达到相同的结果(有更多点击)。例如,为了安装一个数据库,通过运行SQL脚本,您至少需启动SQL Server Management Studio,打开SQL文件(使用文件->->打开->文件的命令) ,然后运行它(使用查询->执行命令)。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐