我无法使用DATA_SOURCE选项创建Azure外部表

时间:2017-05-10 14:16:04

标签: sql-server azure-sql-database

我正在尝试跨数据库查询并通过以下方式设置外部数据源:

CREATE EXTERNAL DATA SOURCE ExampleDataSource
WITH ( 
    TYPE = RDBMS,
    LOCATION = 'example.database.windows.net',
    DATABASE_NAME = 'Database2',
    CREDENTIAL = "credentials"
);

之后,我创建了一个弹性数据库池并将我的数据库添加到它: enter image description here

从我一直在阅读的内容中,我应该做的就是这一切。但它不起作用。这是尝试在第一个数据库上创建的外部表:

CREATE EXTERNAL TABLE [dbo].[tblEmployee](
    [EmployeeId] [UNIQUEIDENTIFIER] NOT NULL,
    [SecurityIdentifier] [NVARCHAR](255) NOT NULL,
    [BatchId] [UNIQUEIDENTIFIER] NULL,
    [FirstName] [NVARCHAR](50) NULL,
    [LastName] [NVARCHAR](50) NULL,
    [EmailAddress] [NVARCHAR](100) NULL,
    [PhoneNumber] [NVARCHAR](50) NULL,
    [NTAccount] [NVARCHAR](50) NULL,
    [DistinguishedName] [NVARCHAR](1024) NULL,
    [Title] [NVARCHAR](100) NULL,
    [Department] [NVARCHAR](50) NULL,
    [Company] [NVARCHAR](50) NULL,
    [ManagerDistinguishedName] [NVARCHAR](1024) NULL,
    [JpegPhoto] [VARBINARY](MAX) NULL,
    [Office] [NVARCHAR](50) NULL,
    [CountryCode] [INT] NULL,
    [DomainName] [NVARCHAR](50) NULL,
    [LocaleId] [UNIQUEIDENTIFIER] NULL,
    [Deleted] [BIT] NOT NULL,
 CONSTRAINT [PK_tblEmployee] PRIMARY KEY NONCLUSTERED 
(
    [EmployeeId] ASC
)
WITH 
(
    DATA_SOURCE = ExampleDataSource
) ON [PRIMARY]
) 

ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO

错误:

Msg 155, Level 15, State 1, Line 34
'DATA_SOURCE' is not a recognized  option.
Msg 102, Level 15, State 1, Line 34
Incorrect syntax near 'ExampleDataSource'.

关于我做错的任何想法?

1 个答案:

答案 0 :(得分:2)

问题是由PK或CREATE EXTERNAL TABLE上的所有额外内容引起的。我知道我需要EXTERNAL TABLE与原始表相同的模式,所以我只是从原始表创建了一个模式脚本,并添加了EXTERNALWITH的东西。所以删除所有额外的东西解决了这个问题。

CREATE EXTERNAL TABLE [dbo].[tblEmployee](
    [EmployeeId] [UNIQUEIDENTIFIER] NOT NULL,
    [SecurityIdentifier] [NVARCHAR](255) NOT NULL,
    [BatchId] [UNIQUEIDENTIFIER] NULL,
    [FirstName] [NVARCHAR](50) NULL,
    [LastName] [NVARCHAR](50) NULL,
    [EmailAddress] [NVARCHAR](100) NULL,
    [PhoneNumber] [NVARCHAR](50) NULL,
    [NTAccount] [NVARCHAR](50) NULL,
    [DistinguishedName] [NVARCHAR](1024) NULL,
    [Title] [NVARCHAR](100) NULL,
    [Department] [NVARCHAR](50) NULL,
    [Company] [NVARCHAR](50) NULL,
    [ManagerDistinguishedName] [NVARCHAR](1024) NULL,
    [JpegPhoto] [VARBINARY](MAX) NULL,
    [Office] [NVARCHAR](50) NULL,
    [CountryCode] [INT] NULL,
    [DomainName] [NVARCHAR](50) NULL,
    [LocaleId] [UNIQUEIDENTIFIER] NULL,
    [Deleted] [BIT] NOT NULL)
WITH 
(
    DATA_SOURCE = ExampleDataSource
)