How to add external table with computed column in SQL project in Visual Studio

Piotr Siwka 0 Reputation points
2024-02-07T09:23:04.7733333+00:00

Hi Everyone, SSDT / Visual Studio expert is needed, right now
In Azure SQL Managed Instance in database I've got External Table with Computed Column:

CREATE EXTERNAL TABLE [ExternalTableSchema].[ExternalTableName]
(
	[MANDT] [varchar](3) NOT NULL,
	[COSTING_DATE] [varchar](8) NOT NULL,
	[FILENAME]  AS CAST(filepath() AS NVARCHAR(255))
)
WITH (
	 DATA_SOURCE = [ExternalDataSource]
	,LOCATION = N'ABC/XYZ'
	,FILE_FORMAT = [Parquet]
	,REJECT_TYPE = VALUE
	,REJECT_VALUE = 0)

CreateExternalTable

ColumnsInSSMS

And in SSMS everything is working as expected: QueryResults

But when I add it to Visual Studio SQL Project I've got error - "SQL46010: Incorrect syntax near AS.": VisualStudio

I know that for standard table it is possible to add Computed Column in SQL Project but for external table it seems it's creating some errors. So here is my question - DOES ANYONE KNOW HOW TO SOLVE THAT KIND OF ISSUE AND ADD THAT TO REPOSITORY?

SQL Server | Other
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Amira Bedhiafi 41,111 Reputation points Volunteer Moderator
    2024-02-07T14:15:44.9333333+00:00

    External tables, by their nature, are meant to provide a SQL-like interface to data stored outside of the SQL Database or Managed Instance, such as Azure Blob Storage or Azure Data Lake. They are defined in SQL but do not support all the features that regular tables do, such as indexing or computed columns, in the traditional sense. However, your SQL definition for creating an external table with a computed column (FILENAME in this case) is syntactically correct and should work in Azure SQL Managed Instance. The challenge comes when trying to integrate this into a SQL project in Visual Studio, as SSDT might not fully support or expect computed columns in the definition of external tables. My recommendations for solutions you can integrate into SSDT/Visual Studio : Instead of defining the computed column directly within the external table definition, you might handle the computation of such columns in a pre-processing step (example a stored procedure) Although not ideal, manually editing the project files (.sqlproj and related .sql scripts) might bypass some of the validation errors you're encountering. You can use post-deployment scripts in SSDT to execute SQL code that SSDT does not natively understand or support in the design-time environment. This means you could potentially create the external table without the computed column in the SSDT design-time environment but then add the computed column in a post-deployment script.


  2. Erland Sommarskog 128.7K Reputation points MVP Volunteer Moderator
    2024-02-07T22:58:25.32+00:00

    You would need to slap a view on top of the external table.


  3. ZoeHui-MSFT 41,536 Reputation points
    2024-02-08T05:30:50.42+00:00

    Hi @Piotr Siwka,

    A little bit same as IIF in condition - SQL46010: Incorrect syntax near ).

    You may raise the issue to DC community to check if it is a known issue.

    Regards,

    Zoe Hui


    If the answer is helpful, please click "Accept Answer" and upvote it.


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.