在Azure SQL DbB中将记录从一个数据库插入另一个数据库 [英] Insert record from one DB to another in the Azure SQL DbB

查看:90
本文介绍了在Azure SQL DbB中将记录从一个数据库插入另一个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我正在使用一些外部表来进行一些处理。我可以使用弹性查询从另一个数据库中获取数据。我想从一个DB的存储过程插入到另一个DB。是否可以在Azure SQL DB中使用?其中一个选项是在Azure SQL DB中嵌入.net
程序集,并从Assembly和.net函数中调用Azure函数或内部代码将连接到将获取INSERT的DB。有没有其他方法可以直接在两个Azure SQL DB之间实现它?

I am using some external tables to do some processing. I can use elastic-query to fetch data from another DB. I want to insert from the Stored Procedure of one DB to another DB. Is it possible in the Azure SQL DB? One of the option is embedding .net assembly in the Azure SQL DB and calling the Azure function or internal code from within the Assembly and .net function will have connection to the DB that will get the INSERT into. Is there any other way to achieve it directly between two Azure SQL DBs?

提前致谢。

Thanks in advance.

GB

推荐答案

嗨  GangadharB, 

Hi GangadharB, 

首先,您需要创建一个数据库作用域凭据,然后使用该凭证创建外部数据源。

First you need to create a database scoped credential, then create an external datasource using that credential.

下一步是创建一个具有相同凭证的外部表定义为来源。

Next step is to create an external table that has the same definition as the source.

然后您可以使用该表。 

Then you can use the table. 

您应该可以使用以下内容作为模板。

You should be able to use the following as a template.

创建数据库SCOPED  CREDENTIAL [CRED_NAME] IDENTITY = N'USERNAME',SECRET = N'PASSWORD'
$
GO



$



b创建外部数据源。您的外部数据源为


   TYPE = RDBMS,

   LOCATION = N'YOURSERVER.database.windows.net',

   DATABASE_NAME = N'YOURDATABASE',

   CREDENTIAL = [CRED_NAME]



GO



$
CREATE EXTERNAL TABLE [dbo]。[NameOfTableOnOtherDB](  

[LogID] [int]  NOT NULL ,

[ClientIP] [varchar](50)NULL,

[ProgramName] [varchar](200)NULL,

[HostName] [varchar ](50)NULL,

[LoginName] [varchar](50)NULL,

< span style ="white-space:pre"> [ConnectionCount] [int] NULL,

[InsertedDate] [datetime] NULL,

 )



  WITH



 (



  DATA_SOURCE = YourExternalDataSource



 );





SELECT * FROM [dbo]。[NameOfTableOnOtherDB]

CREATE DATABASE SCOPED  CREDENTIAL [CRED_NAME] WITH IDENTITY = N'USERNAME', SECRET = N'PASSWORD'
GO




CREATE EXTERNAL DATA SOURCE YourExternalDataSource WITH
(
    TYPE = RDBMS,
    LOCATION = N'YOURSERVER.database.windows.net',
    DATABASE_NAME = N'YOURDATABASE',
    CREDENTIAL = [CRED_NAME]
)
GO


CREATE EXTERNAL TABLE [dbo].[NameOfTableOnOtherDB](   
[LogID] [int]  NOT NULL,
[ClientIP] [varchar](50) NULL,
[ProgramName] [varchar](200) NULL,
[HostName] [varchar](50) NULL,
[LoginName] [varchar](50) NULL,
[ConnectionCount] [int] NULL,
[InsertedDate] [datetime] NULL,
 )

 WITH

 (

 DATA_SOURCE = YourExternalDataSource

 );


SELECT * FROM [dbo].[NameOfTableOnOtherDB]


这篇关于在Azure SQL DbB中将记录从一个数据库插入另一个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆