在Visual Studio Code中使用MSSQL
上一篇講了在Mac上用docker安裝mssql,這篇來說怎麼用Visual Studio Code下sql cmd
首先,當然要先有VSCode了
接下來按ctrl+shift+p
(Mac的話就是command+shift+p
)
![[Command Palette] [Command Palette]](/2016/11/24/VSCode-with-MSSQL/img1.png)
然後選擇install extension
(可以直接打install縮小搜尋範圍)
選完後,左邊就會跳出一個extensions的視窗
再輸入mssql
,就會看到,有兩個,選owner是Microsoft的後,按install
![[Extensions] [Extensions]](/2016/11/24/VSCode-with-MSSQL/img2.png)
安裝後,需要重新啟動Visual Studio Code才行
裝好之後,一樣先按ctrl+shift+p
,然後打進sql後會列出相關的指令
![[Sql Commands] [Sql Commands]](/2016/11/24/VSCode-with-MSSQL/img3.png)
當然要先從connect開始了…
一開始會先說,會把目前的編輯語言改成sql,就改吧QQ
然後選Create connection profile
![[Create Connection Profile] [Create Connection Profile]](/2016/11/24/VSCode-with-MSSQL/img4.png)
依序輸入
- Server Name (沒意外的話輸入localhost就好)
- Database Name(可按enter跳過)
- User Name(輸入sa)
- Password(輸入啟動sql的docker時設定的那串密碼)
- 是否要存密碼(要不要yes就見仁見智了)
- 為這個profile取個名字(可按enter跳過)
都好了之後,可以在又下方檢查是不是有連線成功了
![[Connected to Sql Server] [Connected to Sql Server]](/2016/11/24/VSCode-with-MSSQL/img5.png)
開個新檔案後,在右下方的檔案類型把他換成sql(原本是plain text)
![[Current file type] [Current file type]](/2016/11/24/VSCode-with-MSSQL/img6.png)
然後,直接輸入
|
|
按ctrl+shift+p
後,先輸入sql後,選擇Execute Query
![[Select execute sql query] [Select execute sql query]](/2016/11/24/VSCode-with-MSSQL/img7.png)
就可以看到輸出結果了
![[Executed result] [Executed result]](/2016/11/24/VSCode-with-MSSQL/img8.png)