惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 三生石上(FineUI控件)
美团技术团队
Last Week in AI
Last Week in AI
WordPress大学
WordPress大学
L
LangChain Blog
雷峰网
雷峰网
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园 - 叶小钗
Engineering at Meta
Engineering at Meta
腾讯CDC
Recent Announcements
Recent Announcements
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
博客园 - 司徒正美
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
C
Check Point Blog
小众软件
小众软件
V
Visual Studio Blog
V
V2EX
F
Full Disclosure
J
Java Code Geeks
MongoDB | Blog
MongoDB | Blog
罗磊的独立博客
人人都是产品经理
人人都是产品经理
量子位
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
Microsoft Security Blog
Microsoft Security Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
博客园 - 【当耐特】
博客园_首页
Y
Y Combinator Blog
N
Netflix TechBlog - Medium
酷 壳 – CoolShell
酷 壳 – CoolShell
Stack Overflow Blog
Stack Overflow Blog
Recorded Future
Recorded Future
G
Google Developers Blog
Vercel News
Vercel News
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
U
Unit 42
爱范儿
爱范儿
Jina AI
Jina AI

博客园 - 青玄鸟

.NET 中优雅处理 Server-Sent Events 请求取消 vue3.0 + ts 实现上传工厂(oss与cos) Dapr 订阅者参数无法正确反序列化问题 .NET 代码整洁手册 Blazor项目通过docker和nginx部署为静态站点的步骤 Moq mock 方法返回null空指针异常 基于接口隔离原则的依赖注入实现 HttpClient with Stream HttpClient partial update HttpClient 基本使用 值对象的封装 只读集合类型属性实现 适配器模式 模板模式 最少知识原则 单例模式 抽象工厂 简单工厂、工厂方法、抽象工厂 工厂方法模式
使用 Visual Studio Code创建和执行T-SQL
青玄鸟 · 2019-07-24 · via 博客园 - 青玄鸟

建议使用微软最新推出的Axure Data Studio体验比在vs code中使用插件更好

安装mssql扩展

在扩展中搜索“sql”,在搜索结果中选择“SQL Server (mssql)”

创建sql文件

  1. File > New File 或者使用快捷键 Ctrl+N. Visual Studio Code 默认会打开一个文本文件.

  2. 在下方的状态条中选择 Plain Text ,然后搜索“sql”,在语言下拉框中选择sql 。

连接SQL Server

  1. 快捷键 Ctrl+Shift+P 或 F1 打开命令面板.

  2. 输入sql展示mssql 命令,选择MS SQL: Connect

  3. 选择 MS SQL: Manage Connection Profiles 命令行.

  4. 选择 Create to create a new connection profile for your SQL Server.

  5. 根据提示逐步完成连接的属性,在指定所有属性值后,按回车键继续(建议第一步直接输入连接字符串,快速完成设置)

  6. 在下方状态条验证连接是否成功

创建数据库

  1. 在之前创建的sql文件中,输入sql展示可编辑的代码片段列表

  2. 选择 sqlCreateDatabase.

  3. 在代码片段中, 输入TutorialDB 替换 'DatabaseName'

    -- Create a new database called 'TutorialDB'
    -- Connect to the 'master' database to run this snippet
    USE master
    GO
    IF NOT EXISTS (
       SELECT name
       FROM sys.databases
       WHERE name = N'TutorialDB'
    )
    CREATE DATABASE [TutorialDB]
    GO
    
  4. 使用快捷键 Ctrl+Shift+E 执行 T-SQL 命令.

创建表

  1. 删除代码编辑窗口中的创建数据库的内容

  2. 使用 Ctrl+Shift+P or F1 打开命令面板.

  3. 输入sql展示 mssql 命令, 选择MS SQL: Use Database 命令.

  4. 选择新建的 TutorialDB 数据库.

  5. 在编辑器中,输入sql展示可编辑的代码片段列表 ,选择 sqlCreateTable,然后回车.

  6. 在代码片段中, 输入 Employees 作为表名

  7. 然后输入 dbo 作为表的schema .

  8. 修改列名称

    
    EmployeesId INT NOT NULL PRIMARY KEY,
    Name [NVARCHAR](50)  NOT NULL,
    Location [NVARCHAR](50)  NOT NULL
    Press Ctrl+Shift+E to create the table.
    
  9. 使用快捷键 Ctrl+Shift+E 执行 T-SQL 命令

插入和查询

  1. 使用以下语句插入数据,然后查询.

    -- Insert rows into table 'Employees'
    INSERT INTO Employees
      ([EmployeesId],[Name],[Location])
    VALUES
      ( 1, N'Jared', N'Australia'),
      ( 2, N'Nikita', N'India'),
      ( 3, N'Tom', N'Germany'),
      ( 4, N'Jake', N'United States')
    GO
    -- Query the total count of employees
    SELECT COUNT(*) as EmployeeCount FROM dbo.Employees;
    -- Query all employee information
    SELECT e.EmployeesId, e.Name, e.Location 
    FROM dbo.Employees as e
    GO
    
    
  2. 使用快捷键 Ctrl+Shift+E 执行命令,结果如下