SQL Server 2005 Command Line Tool “SQLCMD” – Part I

Microsoft shipped the SQL Server 2005 command line tool “SQLCMD” along with SQL Server. This SQLCMD replaces the old ISQL command line utility and the OSQL utility. This series will illustrate the various ways of using the SQL Server 2005 command line utility “SQLCMD”.

When “SQLCMD” is run from the MS-DOS command prompt, it uses the OLE DB provider and when it executed from the SQL Server management studio, it uses .NET SQLClient for execution.

[@more@]

Method 1

SQLCMD can be used as an interactive command line SQL tool. Let us see all the options that are available in the SQLCMD tool. Execute the following command in MS-DOS prompt.

 
 

The following results are returned. [Refer Fig 1.0]

 
  
 

Method 2

SQLCMD can be used as an interactive command line SQL tool. The example below illustrates how to connect to SQL Server and query the server name and version number. Execute the following command at the MS-DOS command prompt as shown below. You will get the following results.

 
 

Note: HOME is the servername and –E means we are using windows authentication.

Method 3

The above command can be executed using SQL Authentication as shown below. This example shows how to connect to a named instance of the SQL Server using SQL authentication.

 
 

Note: HOME is the hostname, SQLEXPRESS is the instance name servername and –U and –P mean we are using SQL authentication.

Method 4

The following example illustrates how to connect to a named instance of the SQL Server using Hostname and PORT number.

 
 

Note: Home is the hostname, 7005 is the PORT number of the named instance SQLEXPRESS.

Method 5

The following example shows how to connect to a SQL Server instance using windows authentication and execute a command directly instead of interactive SQL.

 
 

Note: Home is the hostname, 7005 is the PORT number of the named instance SQLEXPRESS. [Refer Fig 1.2]

mak_CLT_image002.jpg
Fig 1.2

Method 6

The following example illustrates how to connect to a SQL Server instance using windows authentication, execute a command directly on to a database and get the results instead of interactive SQL.

 
 

Note: Home is the hostname, 7005 is the PORT number of the named instance SQLEXPRESS and test is the database name.

Conclusion

Part 1 of this series illustrated a few of the various ways of using the SQL Server 2005 command line utility “SQLCMD”. In future articles, we will discuss more of the SQLCMD utility features.

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/1697933/viewspace-896426/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/1697933/viewspace-896426/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值