本文共 8445 字,大约阅读时间需要 28 分钟。
批量关停azure vm
In this new article, we will use Visual Studio to connect to a SQL Server Database Installed in a Virtual Machine in Azure.
在这篇新文章中,我们将使用Visual Studio连接到安装在Azure虚拟机中SQL Server数据库。
Visual Studio is one of the most popular development tools in the world and connecting to Azure with Visual Studio is a very common need.
Visual Studio是世界上最受欢迎的开发工具之一,通过Visual Studio连接到Azure是非常普遍的需求。
We will modify an existing SQL Server table in Azure from Visual Studio. Later we will create a stored procedure and finally, we will create an inline table-valued function.
我们将从Visual Studio修改Azure中现有SQL Server表。 稍后,我们将创建一个存储过程,最后,我们将创建一个内联表值函数。
In the , select Browse All➜Virtual machines and select the Virtual Machine with SQL Server installed.
在 ,选择“浏览所有”➜“虚拟机”,然后选择安装了SQL Server的虚拟机。
Copy the Machine name which is also the SQL Server name (if you are using the default instance).
复制计算机名称,该名称也是SQL Server名称(如果使用的是默认实例)。
Click on Server Explorer and in Data Connection, select Add Connection.
单击服务器资源管理器,然后在数据连接中,选择添加连接。
Use the server name of the step 2, unless the SQL Server instance is not a default instance of SQL Server and specify the SQL Server Authentication user name and password. Finally, write the Database name. In this example, we will use the AdventureWorks2014 database.
除非SQL Server实例不是SQL Server的默认实例,否则请使用步骤2的服务器名称,并指定SQL Server身份验证用户名和密码。 最后,输入数据库名称。 在此示例中,我们将使用AdventureWorks2014数据库。
In order to see the connection, press the refresh button and you will be able to see the new connection
为了查看连接,请按刷新按钮,您将能够看到新的连接
To view the data of the table, right click on it and select Show Table Data.
要查看表的数据,请右键单击它,然后选择“显示表数据”。
You will be able to see the table data.
您将能够看到表格数据。
To insert new data, go to the last row and write new data. In this example, we are adding the IT department.
要插入新数据,请转到最后一行并写入新数据。 在此示例中,我们将添加IT部门。
In order to verify that the new data was added, connect to your VM in Azure.
为了验证是否添加了新数据,请连接到Azure中的VM。
Open the SQL Server Management Studio
打开SQL Server Management Studio
Verify that the table has the new data.
验证该表具有新数据。
You will notice that the new row created on step 8 was successfully added.
您将注意到在步骤8中创建的新行已成功添加。
Now, we are going to create a stored procedure with a parameter. In Visual Studio, right click on Stored Procedures and select Add New Stored Procedure.
现在,我们将创建带有参数的存储过程。 在Visual Studio中,右键单击“存储过程”,然后选择“添加新的存储过程”。
By default, you will have this code:
默认情况下,您将具有以下代码:
In this example, we will create a stored procedure that will show the department information if we specify the name of the department. The @name will be the parameter with is the name of the department. The code will be like this:
在此示例中,我们将创建一个存储过程,如果我们指定部门名称,该存储过程将显示部门信息。 @name将是带有部门名称的参数。 代码将如下所示:
CREATE PROCEDURE [dbo].[departmentinfo] @name nvarchar(30) ASSELECT [DepartmentID] ,[Name] ,[GroupName] ,[ModifiedDate] FROM [AdventureWorks2014].[HumanResources].[Department] where name=@name
The stored procedure name is departmentinfo and the input parameter is name. It shows all the information of the department table of the database Adventureworks where the name is equal to the parameter. Once the stored procedure code is done, press update.
存储过程的名称为departmentinfo,输入参数为name。 它显示名称等于该参数的数据库Adventureworks的部门表的所有信息。 一旦存储过程代码完成,请按更新。
In the Previous Database Updates window, press the update database button.
在“以前的数据库更新”窗口中,按更新数据库按钮。
You can verify in the SSMS of the Azure VM that the stored procedure was created successfully.
您可以在Azure VM的SSMS中验证存储过程已成功创建。
To execute the stored procedure, on Visual Studio, right click on the stored procedure and select Execute.
要执行存储过程,请在Visual Studio上右键单击存储过程,然后选择执行。
In the value section specify a value. Check the step 8 to verify valid values. The stored procedure receives the Department name and returns the information of the department. In this example, we are inserting the IT name. Press OK.
在值部分中,指定一个值。 检查步骤8以验证有效值。 存储过程接收部门名称并返回部门信息。 在此示例中,我们将插入IT名称。 按确定。
As you can see, the stored procedure was executed successfully. You can see the T-SQL code generated and the results of the stored procedure. It is showing the information related to the department name specified as input.
如您所见,存储过程已成功执行。 您可以看到生成的T-SQL代码和存储过程的结果。 它显示与指定为输入的部门名称有关的信息。
Finally, let’s create an Azure function using Visual Studio. We will use the Employee table that contains the following information:
最后,让我们使用Visual Studio创建一个Azure函数。 我们将使用Employee表,其中包含以下信息:
The table contains Employees information. We will send the the function the LoginID and we want to receive the age of the employee based on the birthdate. For example, the login Adventure-works\ken0 has 46 years.
该表包含员工信息。 我们将向该函数发送LoginID,并希望根据出生日期接收员工的年龄。 例如,登录Adventure-works \ ken0有46年。
To create a Functions right click on Functions in Visual Studio.There are several types of functions:
要创建函数,请在Visual Studio中的“函数”上单击鼠标右键。有几种类型的函数:
Scalar-valued Function: They return a scalar value.
标量值函数:它们返回标量值。
Write the following code to create the function:
编写以下代码以创建函数:
CREATE FUNCTION [dbo].[returnage]( @LoginId nvarchar(26))RETURNS TABLE AS RETURN( SELECT DATEDIFF(yy,BirthDate,GETDATE()) as age FROM [AdventureWorks2014].[HumanResources].[Employee] WHERE LoginId = @LoginId)
The Function name is returnage. It receives de loginId from the Employee table and the functions calculates the age of the employee with using the BirthDate.
功能名称是退货。 它从Employee表中接收de loginId,并且这些函数使用BirthDate计算雇员的年龄。
Once your code is done, press Update and repeat the step 16.
完成代码后,请按Update并重复步骤16。
To verify that the function was created press the refresh icon. You will be able to see the returnage function.
要验证该功能已创建,请按刷新图标。 您将能够看到退货功能。
If you expand the function, you will be able to see that the loginID is the input parameter and the age the column returned.
如果展开该功能,您将能够看到loginID是输入参数,并且返回该列的使用期限。
To test the function, right click on the function and press Execute.
要测试该功能,请右键单击该功能,然后按执行。
Write a LoginId, check the figure 21 for valid values and press OK.
编写一个LoginId,检查图21中的有效值,然后按OK。
You will be able to see the function execution T-SQL code and the result. The LoginID adventure-works\roberto0 has the age of 41 years.
您将能够看到函数执行的T-SQL代码和结果。 LoginID adventure-works \ roberto0的年龄为41岁。
Visual Studio is a great and easy to use tool to program. In this article we show how simple is to connect to a VM machine in Azure and create SQL Server stored procedures, functions and to update the information.
Visual Studio是一款出色且易于使用的编程工具。 在本文中,我们展示了连接到Azure中的VM机器并创建SQL Server存储过程,函数以及更新信息的简单程度。
翻译自:
批量关停azure vm
转载地址:http://fbiwd.baihongyu.com/