Error 0xc002f210 - database

I have just started learning SQL Server, I am trying to use Import Export wizard to import data from excel file to one of the table in the database. But I am getting an error 0xc002f210.
I understood only that it is taking length of excel file cell as 255 but the SQL Server table length is different. I am unable to understand why it is happening.
Validating (Error)
Warning 0x802092a7: Data Flow Task 1: Truncation may occur due to inserting data from data flow column "Name" with a length of 255 to database column "Name" with a length of 50.
(SQL Server Import and Export Wizard)
Warning 0x802092a7: Data Flow Task 1: Truncation may occur due to inserting data from data flow column "GroupName" with a length of 255 to database column "GroupName" with a length of 50.
(SQL Server Import and Export Wizard)
Error 0xc002f210: Preparation SQL Task 1: Executing the query "TRUNCATE TABLE [HumanResources].[Department]
" failed with the following error: "Cannot truncate table 'HumanResources.Department' because it is being referenced by a FOREIGN KEY constraint.". Possible failure reasons: Problems with the query, "ResultSet" property not set correctly, parameters not set correctly, or connection not established correctly.
(SQL Server Import and Export Wizard)

So the error you are receiving is different from the warnings that you are getting. The warnings are simply informing you that you are taking a larger column and putting it into a smaller column, so there is the possibility of data truncation.
The error will give you some insight into the purpose of using a Foreign Key Constraint. The technet article will give you an in depth understanding of it if you read through it.
TechNet
But essentially, referential integrity by way of foreign key constraints make it so that the "link" between data cannot be broken on the Primary Key side (table "Department"). In order to delete data from the Primary Key table, you must first either remove the foreign key, or delete the data first from the Foreign Key table.
You should re-evaluate two things:
1) Whether you actually should be truncating the Primary key table
2) Which table has a foreign key linked to the Department table's primary key.

Related

Insert rows into SQL Server table with a primary key with SSIS

I have an SSIS package that I use to pass data from an Excel workbook into the SQL Server table:
My Excel file grows constantly with new records, therefore I've defined a primary key in the SQL Server table to avoid inserting duplicates, but basically I'm inserting the whole workbook each time.
I now have a problem, where either the whole package fails completely because it attempts to pass duplicate values into a table with PK, or if I set the Error Output of the destination to "Redirect row", the package gets executed successfully with the following message:
Data Flow Task, SSIS.Pipeline: "OLE DB Destination" wrote 90 rows
but no new rows are actually added to the table.
If I remove the PK constraint and add a trigger to remove duplicates on insert, it would work, but I would like to know the proper way to do this.
To make the design "work," with an error table, change your batch commit size to 1 in the OLE DB Destination. What's happening is that it's trying to commit the 90 rows but as there's at least 1 bad row in there, the whole batch fails.
The better approach will be to add a Lookup Component between the data conversion and the destination. The output of the Lookup will be the "No Match Found" output path and that is what will feed into the OLE DB Destination. The logic is that you're going to attempt to lookup the existing key in the target table. The No Match Found is what it sounds like, the row doesn't exist so therefore, shove it into the table and you won't have a PK conflict*.
* I still got a PK conflict but it's not there. In this case, you have duplicates/repeated keys in your source data and the same issue with regard to batch size is obscuring it. We're adding 2 rows with PK 50. PK 50 doesn't exist so it passes the lookup but the default batch size means both of those rows are going to be inserted in a single shot. Which violates referential integrity and then gets rolled back.

Snowflake Insert/Update Error in Alteryx "Primary Key required for update option"

Having some issues updating a Snowflake database by inserting/updating records based on a primary key. Getting this error below:
enter image description here
My set up:
I have set a primary key in the Snowflake DB "PRIMARY_KEY", using the statement:
ALTER TABLE [TABLE NAME] ADD PRIMARY KEY (PRIMARY_KEY);
enter image description here
I have the same field "PRIMARY_KEY" in my Alteryx DB that I am using to write to the Snowflake table.
enter image description here
My output options are:
enter image description here
I am using the Snowflake Driver ODBC Driver 2.23.2
Is there anything I can do to fix this? Thanks!
You can define Primary Keys in Snowflake but Snowflake does not enforce them, in all honesty it's just informational and useful for tools that use that definition.
The error message you're receiving is likely an Alteryx error, not Snowflake. Is there a way to see what code is being generated by Alteryx? I suspect the generated code to run an update is missing what to update by.

Foreign Key Constraint Violation MS-SQL: useless error without details

Violating a simple foreign key contraints in MS-SQL generates following useless error-message:
Error: The INSERT statement conflicted with the FOREIGN KEY constraint
"FK_employee". The conflict occurred in database "AgentAndAgency", table "dbo.employee", column 'id'.
SQLState: 23000
ErrorCode: 547
Missing is the detail, which key is causing the foreign key contraint, so, e.g. PostgreSQL would say in the same situation:
Error: inserting into table employement violates foreign key contraint- „FK_employee“
Details: key (employee_id)=(958980) does not exist in table „employee“.
MS-SQL does not provide this information, which makes it completely useseless (I'm bulk-inserting thoundsands of records).
Question: how can I make MS-SQL tell me at least one missing key?
Because the data may contain multiple errors, the "identify one error, fix that and iterate" technique tends not to work out well.
No server, so far as I'm aware, will identify all missing keys - they terminate the work as soon as they've identified that an error has occurred1 since the presence of just a single error may mean that the entire task needs to be aborted, rather than the data needing fixing.
To identify all of the errors, a better approach is to perform your bulk-insert into a staging table that doesn't have any constraints. Then write a query that left joins to the employee table and identifies all missing keys.
1Rather than potentially wasting resources by attempting to identify the complete set. But from a "relational-purist" perspective, that's what they ought to do - since we try to keep everything set-based, the errors ought to be sets too.
Instead of the update, do a SELECT from your update data WHERE employee_id NOT IN (SELECT employee_id FROM employee)
Should give you the list of missing employee_ids

Accessing Oracle case sensitive ROWID from MS SQL Server

I am having a oracle table where the ROWID column is having data which is duplicate but as the field is case sensitive its considering it as 2 different rows eg. 'Test' and TEST are considered different.
when i am accessing this from MS SQL Server using ODAC, i am getting the error saying System.Data.ConstraintException:Failed to enable constraints.one or more rows contains values violating non null,unique or foreign key constraints.
Any way to query the data using ODAC?
Anyone faced similar issue?

Unable to build SQL Server OLAP Cube when there is no rows corresponding to foreign key in a table

I am new to SQL Server OLAP Cubes. I am having the following issue like
ex I have purchase order and invoice tables which are used in data source view. These two tables are related by purchase order ID which have one to many relationship with invoices.
I am getting the following error for the purcahse orders which i dont have invoices
Errors in the OLAP storage engine: The attribute key cannot be found when processing: Table: purchase order
Can anyone throw some light on this to help me
The most common causes for this error is processing order and NULLs in fact table.
Make sure you process the dimension before processing the measure group.
When key values in the fact table has NULL values, SSAS by default treats it as 0 for INT and '' (Blank) for Char data types. Make sure fact keys don't have NULL values. If there are nulls, one solution is to use a default unknown member in the dimension table (usually -1) and replace null in the fact table to -1.

Resources