Tuesday 6 August 2019

Check constraints option in oledb destination in SSIS


This option is enabled when we are selecting Data access mode to “Table or view – fast load”
  

By default check, constraints value is checked.
When we are selecting the data access mode to “Table or view – fast load” our destination treated as bulk insert. But our destination may have constraints.
Constraints in SQL Server are predefined rules and restrictions that are enforced in a single column or multiple columns, regarding the values allowed in the columns, to maintain the integrity, accuracy, and reliability of that column’s data. Constrain maybe
  •   PRIMARY KEY
  •   FOREIGN KEY
  •   CHECK
  •   DEFAULT
  •   NOT NULL
  •   UNIQUE

Let’s see the demo how it works
Here I am creating a table with check constraints.
CREATE TABLE Sales_Table (
    [SalesOrderNumber] varchar(50),
    [SalesAmount] varchar(50),
    [UnitPrice] varchar(50),
    [ExtendedAmount] varchar(50),
    [TaxAmt] varchar(50),
    LoadDate DateTime DEFAULT getdate(),
    LoadBy    VARCHAR(50),
CONSTRAINT check_LoadDate     CHECK (LoadDate <= Getdate())
)

It checks the load date. Load date must be today date or less than it.
I am taking data flow task and source as a flat file
  

Column mapping
  

Now I am taking derive column transformation to add the load date column and assigning the load date through expression.
  

Now I am taking oledb destination
And mapping the columns
   


Unchecking the Check constraints.
 
\

Now I am running this package.
  

Load date less than Today date.
   
 

Data loaded successfully. Now I am adding the load date to future date.
  

Check constraint to unchecked.
  

Now running this package.
Data loaded successfully.
  

Even though it violated the check constraint it loads the data.
Now I have checked the check constraint.
  

Running the package.
                         

Date is future date so it will violate the rule.
Package failed.  

 

See the error.
[OLE DB Destination [40]] Error: SSIS Error Code DTS_E_OLEDBERROR.  An OLE DB error has occurred. Error code: 0x80004005.
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The statement has been terminated.".
An OLE DB record is available.  Source: "Microsoft SQL Server Native Client 11.0"  Hresult: 0x80004005  Description: "The INSERT statement conflicted with the CHECK constraint "check_LoadDate". The conflict occurred in database "Test", table "dbo.Sales_Table", column 'LoadDate'.".
[OLE DB Destination [40]] Error: SSIS Error Code DTS_E_INDUCEDTRANSFORMFAILUREONERROR.  The "OLE DB Destination.Inputs[OLE DB Destination Input]" failed because error code 0xC020907B occurred, and the error row disposition on "OLE DB Destination.Inputs[OLE DB Destination Input]" specifies failure on error. An error occurred on the specified object of the specified component.  There may be error messages posted before this with more information about the failure.
[SSIS.Pipeline] Error: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component "OLE DB Destination" (40) failed with error code 0xC0209029 while processing input "OLE DB Destination Input" (53). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.

So we can say that Unchecking “Check Constraints” only turns off the checks for check constraints but Referential and other integrity constraints (NOT NULL, Foreign Key, Unique Key, etc.) continue to be enforced.

9 comments:

  1. Type of credit cards accepted You will need to verify the most frequently encountered credit and debit cards employed by your clients or the card types you want to accept. For more information on merchant account read here.

    ReplyDelete
  2. Thank you so much for providing a very useful informtion about SSIS and throwing light on such a important topic.

    SSIS Postgresql Read

    ReplyDelete
  3. Fire Watch Security Guards provides a wide variety of services to deal with the diverse needs of its clients all over the nation. Get more interesting details about firewatch check out this site.

    ReplyDelete
  4. Thanks for sharing valuable information with us.You can get best business intelligence tools by contacting OFS. More details is on https://www.onefederalsolution.com/

    ReplyDelete
  5. Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing on Msbi online training
    Msbi online training Hyderabad
    Msbi online training India
    Msbi online course
    Msbi course
    Msbi training
    Msbi certification training

    ReplyDelete
  6. Can nicely write on similar topics! Welcome to here you'll find out how it should look. how to hack any phone

    ReplyDelete

If you have any doubt, please let me know.

Popular Posts