Synapsesql pool

Rohit Kulkarni 441 Reputation points
2021-03-22T17:19:19.61+00:00

Hello team,
I want to create the GetDate() in synapse sqlpool for one of the column in the table .

I am using this table in data factory pipeline dynamically. So i can't create select statement. So i need to display current date and time in the select statement for column3.So I need to mention in create table statement.
Please advise.
80351-image.png
Create table Table1
(
column1 nvarchar NULL,
column2 [int] NULL,
CAST(GETDATE() AS datetime) AS column3
)
WITH ( DISTRIBUTION = ROUND_ROBIN, HEAP )

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
0 comments No comments
{count} votes

Answer accepted by question author
  1. Nandan Hegde 36,716 Reputation points MVP Volunteer Moderator
    2021-03-23T07:16:47.763+00:00

    Hey @Rohit Kulkarni ,
    Unfortunatley synapse doesnt allow functions as default constraints.

    CREATE TABLE dbo.doc_exz (column_a INT, column_b varchar(50));  
    GO  
    INSERT INTO dbo.doc_exz (column_a) VALUES (7);  
    GO  
    ALTER TABLE dbo.doc_exz  
      ADD CONSTRAINT DF_Doc_Exz_Column_B  
      DEFAULT getdate() FOR column_b;  
    GO  
    

    The above code would work for Azure SQL database but not synapse.
    you would get the below error:
    An expression cannot be used with a default constraint. Specify only constants for a default constraint.

    So ideally the best way would be to insert getdate() into rows while inserting data into synapse table


0 additional answers

Sort by: Most helpful

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.