上一篇講了在Mac上用docker安裝mssql,這篇來說怎麼用Visual Studio Code下sql cmd

首先,當然要先有VSCode

接下來按ctrl+shift+p (Mac的話就是command+shift+p)

[Command Palette]

然後選擇install extension (可以直接打install縮小搜尋範圍)

選完後,左邊就會跳出一個extensions的視窗

再輸入mssql,就會看到,有兩個,選owner是Microsoft的後,按install

[Extensions]

安裝後,需要重新啟動Visual Studio Code才行

裝好之後,一樣先按ctrl+shift+p,然後打進sql後會列出相關的指令

[Sql Commands]

當然要先從connect開始了…
一開始會先說,會把目前的編輯語言改成sql,就改吧QQ

然後選Create connection profile

[Create Connection Profile]

依序輸入

  • Server Name (沒意外的話輸入localhost就好)
  • Database Name(可按enter跳過)
  • User Name(輸入sa)
  • Password(輸入啟動sql的docker時設定的那串密碼)
  • 是否要存密碼(要不要yes就見仁見智了)
  • 為這個profile取個名字(可按enter跳過)

都好了之後,可以在又下方檢查是不是有連線成功了

[Connected to Sql Server]

開個新檔案後,在右下方的檔案類型把他換成sql(原本是plain text)

[Current file type]

然後,直接輸入

1
SELECT * FROM sys.databases;

ctrl+shift+p後,先輸入sql後,選擇Execute Query

[Select execute sql query]

就可以看到輸出結果了

[Executed result]