본문 바로가기

DBMS/SQL Server

[SQL Server] SQLCMD(SQL Command) 사용하기

 

SQLCMD(SQL Command)

 

명령 프롬프트 상에서 SQL Server 서버에 접속해서 작업을 수행할 수 있도록 해 주는 도구

SSMS의 쿼리 창을 사용하지 않고, 명령 프롬프트에서 동일한 작업을 수행할 수 있다.

 

SQLCMD.EXE를 실행하기 위한 옵션

sqlcmd 
[{ { -U login_id [ -P password ] } | –E trusted connection }] 
[ -N encrypt connection ][ -C trust the server certificate ]
[ -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 ]

SQL Server에 접속하기위한 옵션 중에서는 기본적으로 -U, -P, -S 세 개가 가장 많이 사용된다.
-U와 -P는 SQL Server 인증 모드로 접속할 때의 사용자 및 비밀번호를 지정하기 위한 옵션이며,

-S는 서버 컴퓨터나 명명된 인스턴스를 지정할 경우에 사용되는 옵션이다.

 

 

아무런 옵션을 주지 않고 'SQLCMD'라고만 입력하면 가장 기본적인 접속이다.

SSMS의 쿼리 창에서 사용한 대부분의 SQL문을 동일하게 사용할 수 있다.

 

 

사용자와 서버를 지정하여 접속할 수도 있다.