[VS Code][SQL Server] Visual Studio Code 連線 MS SQL Server 並執行 SQL 語法

熱門文章 (Popular Post)

Posted by : Duran Hsieh 2018-01-16

前言

過去要對 MS SQL Server 進行操作,我們都習慣透過 SSMS 來進行,但常常環境因素(作業系統,如mac) 不方便安裝SSMS,需要遠端連線到有SSMS的主機才能進行操作。而現在,我們透過 Visual Studio Code 也能連線到 MS SQL Server 進行操作,非常方便。

本篇將簡單介紹如何透過 Visual Studio Code 連接MS SQL Server,若有錯誤或任何建議,請各位先進不吝指教。


介紹

Step 1. 開啟 Visual Studio Code → 點選Extension → 輸入mssql → 點選安裝
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514196542221_image.png


Step 2. 點選新增程式 → 輸入檔案名稱 (副檔名為sql)
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514197002321_image.png
註:官網文件建議可以透過快捷鍵 Ctrl +K, M 切換語言
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514197460641_image.png

Step 3. 點選 Ctrl + Shift + P 開啟命令列 ,輸入SQL 找到 connect 命令
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514197686163_image.png


Step 4. 點選 Create connection profile → 輸入 Server name or ADO.NET connection string
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514197785399_image.png
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514197877849_image.png


Step 5. 輸入資料庫名稱
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198375209_image.png


Step 6. 選擇 SQL Login
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198393958_image.png


Step 7. 輸入user name 與 user password
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198427145_image.png
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198452600_image.png


Step 8. 選擇是否儲存密碼
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198474559_image.png


Step 9. 對profile 命名
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198528601_image.png


Step 10. 完成連線
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198661729_image.png


Step 10. 我們輸入 SELECT 語法 → 點選右鍵執行查詢,在右手邊會出現結果
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514198770904_image.png


Step 11. 你可以在結果表格點選右鍵,進行資料儲存
https://d2mxuefqeaa7sj.cloudfront.net/s_050AD0233E63686269DC4A7D88ECA9BD9037D485893E601A84B29F3778C36976_1514199091126_image.png




參考資料

使用 Visual Studio 程式碼來建立和執行 SQL Server 的 TRANSACT-SQL 指令碼https://docs.microsoft.com/zh-tw/sql/linux/sql-server-linux-develop-use-vscode


Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Duran Hsieh @ Duran 的技術冶煉廠 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -