【问题标题】:Azure SQL - Cannot create encrypted master keyAzure SQL - 无法创建加密的主密钥
【发布时间】:2020-04-22 10:19:19
【问题描述】:

我正在尝试为我的数据库创建一个主密钥,因为我按照教程进行跨数据库查询。

教程:https://www.scarydba.com/2016/03/21/cross-database-queries-in-azure-sql-database/

这是与Cannot create master key for master database in azure sql 类似的问题,但我收到了消息:

Msg 15578, Level 16, State 1, Line 1 数据库。请在执行此语句之前将其删除。

...当我尝试创建一个加密的主密钥时。我做错了什么,还有其他选择可以使用 Azure 进行跨数据库调用吗?

我执行以下操作:

CREATE MASTER KEY ENCRYPTION BY PASSWORD='SUPERSTRONGPASSWORD'
GO

问候

【问题讨论】:

    标签: azure-sql-database


    【解决方案1】:

    根据我的经验,在我们创建 Azure SQL 数据库时,主密钥已经创建并存在。

    当我们create master key:

    -- Create a db master key if one does not already exist, using your own password.
    CREATE MASTER KEY ENCRYPTION BY PASSWORD='<EnterStrongPasswordHere>';
    

    由于主密钥已经存在,我们无法创建一个新的。

    在大多数情况下,Azure SQL 数据库跨数据库查询不需要创建主密钥。

    例如,我使用波纹管查询从 Mydatabase 到 Mydatabase2 进行跨数据库查询:

    --The "username" and "password" should be the username and password used to log in into the Customers database.
    CREATE DATABASE SCOPED CREDENTIAL ElasticDBQueryCred
     WITH IDENTITY = '<username>',
     SECRET = '<password>';  
    
     --To create an external data source, execute the following command on the Orders database:
     CREATE EXTERNAL DATA SOURCE MyElasticDBQueryDataSrc WITH
        (TYPE = RDBMS,
        LOCATION = '<server_name>.database.windows.net',
        DATABASE_NAME = 'Customers',
        CREDENTIAL = ElasticDBQueryCred,
    ) ;
    
    --Create an external table on the Orders database, which matches the definition of the CustomerInformation table:
    CREATE EXTERNAL TABLE [dbo].[test]
    ( [id] [int] ,
      [age] [int]
      )
    WITH
    ( DATA_SOURCE = MyElasticDBQueryDataSrc)
    
    --query the table 
    select * from test
    

    Mydatabase2 中的测试表:

    Mydatabase 中的跨数据库查询:

    详情请参考:Get started with cross-database queries。

    希望这会有所帮助。

    【讨论】:

    • 嗨,莱昂,感谢您的回答。关键是,不要创建密钥,因为已经有一个。其次,应将外部表命名为其他数据库中的表。现在效果很好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    • 2021-08-27
    • 1970-01-01
    • 2021-01-24
    • 2011-05-01
    • 2018-08-19
    相关资源
    最近更新 更多