sqlcmd -S server01\SqlSrv2008
sqlcmd -S server01\SqlSrv2008 -d AdventureWorks2008
Syntax
sqlcmd [{ { -U login_id [ -P password ] } | –E trusted connection }] [ -z new password ] [ -Z new password and exit] [ -S server_name [ \ instance_name ] ] [ -H wksta_name ] [ -d db_name ] [ -l login time_out ] [ -A dedicated admin connection ] [ -i input_file ] [ -o output_file ] [ -f < codepage > | i: < codepage > [ < , o: < codepage > ] ] [ -u unicode output ] [ -r [ 0 | 1 ] msgs to stderr ] [ -R use client regional settings ] [ -q "cmdline query" ] [ -Q "cmdline query" and exit ] [ -e echo input ] [ -t query time_out ] [ -I enable Quoted Identifiers ] [ -v var = "value"...] [ -x disable variable substitution ] [ -h headers ][ -s col_separator ] [ -w column_width ] [ -W remove trailing spaces ] [ -k [ 1 | 2 ] remove[replace] control characters ] [ -y display_width ] [-Y display_width ] [ -b on error batch abort ] [ -V severitylevel ] [ -m error_level ] [ -a packet_size ][ -c cmd_end ] [ -L [ c ] list servers[clean output] ] [ -p [ 1 ] print statistics[colon format]] [ -X [ 1 ] ] disable commands, startup script, enviroment variables [and exit] [ -? show syntax summary ]
SELECT LastName
FROM Sales.vSalesPerson
ORDER BY LastName
GO
Running sqlcmd commands
In addition to running Transact-SQL statements in interactive mode, you can also run sqlcmd commands. The commands let you perform actions that cannot be performed by using Transact-SQL. For example, you can use sqlcmd commands to connect to a specific instance of SQL Server or to send query results to a text file. The following code demonstrates how you can use sqlcmd commands along with Transact-SQL in interactive mode:
:Connect server01\SqlSrv2008
:Out C:\Data\SqlCmdOutput.txt
USE AdventureWorks2008
GO
SELECT LastName
FROM Sales.vSalesPerson
ORDER BY LastName
GO
:EXIT
sqlcmd -d AdventureWorks -Q "SELECT LastName FROM Sales.vSalesPerson"
-- 실행 결과 OUTPUT
sqlcmd -i C:\Data\SqlCmdInput.sql -o C:\Data\SqlCmdOutput.txt –u
!!del C:\Data\SqlCmdOutput.txt
SELECT LastName, SalesYTD
FROM Sales.vSalesPerson
ORDER BY LastName
:Out C:\Data\SqlCmdOutput.txt
Editing SQLCMD Scripts with Query Editor : http://msdn.microsoft.com/en-us/library/ms174187.aspx
'SQL Server 2005' 카테고리의 다른 글
SQL의 SHFT 비트 연산 (0) | 2009.01.13 |
---|---|
SQL Server, SANs and Virtualisation (0) | 2009.01.09 |
DB의 Collation (0) | 2009.01.07 |
인덱스 사용중인 상태 체크 (0) | 2009.01.07 |
사용하지 않은 인덱스 찾기 (0) | 2009.01.07 |