0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【備忘録】Sqlcmdのオプション

Last updated at Posted at 2025-01-26

概要

sqlserverでサーバーやユーザー名、パスワードを指定して、任意の環境のDBを操作する際に使用していたコマンドというかステートメント。

よく使うオプション

単体で使うことはほぼない。組み合わせて使う。

オプション 説明
-U ユーザーIDを指定
-P パスワードを指定
-d データベースを指定
-I 識別子を引用符で区切る
-s 区切り文字を指定
-W 余分な空白文字を削除
-Q “コマンドライン クエリ” と終了(goを省略できる)
-o アウトプットファイルを指定
-i インプットファイルを指定
-S インスタンス(サーバー名)を指定

具体例

  • サーバー名Example_Serverにユーザー名user_001でログインし、目的のデータベースsqldb-example001にログインしてsqlを実行し、結果を/data/app/output.datに出力したい。パスワード:Password001where句は適当。
sqlcmd -S Example_Server -U user_001 -P 'Password001' 
       -d sqldb-example001 -Q 'select top 5 * from Example_db where Example_id > 10' 
       -o /data/app/output.dat 

加えて出力するデータを|で区切るなどする場合は-s \|などする。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?