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?
Related
I have MS Access tables that are indexed but accept duplicates. Tables have been transferred to SQL Server and linked to Access.
How do you replicate primary keys that accept duplicates?
You should consider using SSMA
Sql Server Migration Assistant for Access
It can move up tables.
It will move up related data, setup PK columns for you.
It will maintain, and create relationships for you.
It will maintain and create all indexes you have now.
If you just have a few tables, say 2-5 tables? Then sure, just import them and setup the relatonships and indexs your self.
However, the last few migrations of data from Access to SQL server? There was in excess of 80 tables - and HUGE numbers of reatonships, indexes, and of course PK settings. The migration wizard thus can send up all of the tables - and setup all of the tables correctly on SQL server for you. Including PK values, FK values (Foreign Keys (related tables)),
and even constraints are in most cases correctly move up to sql server.
what is nice, is then you can re-link the tables in your Access application, and you now using SQL server for the back end database.
SSMAA can be found here:
https://www.microsoft.com/en-us/download/details.aspx?id=54255
I think you're confusing an "index" with a "primary key".
An "index" is a structure that helps optimise queries. Indexes don't have to be unique. A "primary key" is a logical constraint on a column which requires that all values in the column are unique.
It sounds like what you want to do is import the data into SQL and create an index to help speed up queries, but where that index is not constrained to be unique.
Here's the syntax to do that. Suppose we have some table T:
create table T(i int, j int, k int);
We want to create an index on column i to speed up queries, but i is not unique. To do that we create a regular (non unique) index:
create index MyIndexName on T(i);
As a rule, I tend to name my indexes based on what they are indexing. So in the above case I wouldn't call the index "MyIndexName", I would call it something like ix_T_i.
So the situation is there are two servers pub_server(publisher) and sub_server (subscriber).
There are two databases on pub_server : db1 and db2.
There exists a table xyz_tbl in db1 which is replicated(transactional) to the sub_server (publisher name : publisher_old).
My task is to drop the subscription and article from publisher_old and create a new publisher publisher_new at db2 with same article xyz_tbl and same subscriber sub_server.
Now here is the problem : the xyz_tbl has a computed column. So when I executed the script for publisher_new I get error in Replication Monitor.
Error : The column "column_name" cannot be modified because it is either a computed column or is the result of a UNION operator
I am using #sync_type="replication support only" since table already exists at subscriber (from publisher_old). Then why distributor is trying to perform insertion on subscriber which generates above error.
If at all distributor is trying insertion then how come the replication was working from db1 i.e publisher_old.
How to handle computed columns in replication. I couldn't find any answer.
Please help!
Most of the works are not available for computed columns.Such is updating.
I recommend not to replicate computed column. You can compute it again in your replication db.
Other way is make computed column an actual column, and then replicate.
If you want insert to computed column, then you can make kind property be equal to PersistantReadOnly.
But if calculated column persisted in replication is not replicarted as definition replication of other object fail and if add it should be removed before bcp. and at the end you can add them on subscriber only through creating on publisher (dop and recreate) and replicating bit then you can have problem with FK and indexes.
Is it possible to tell sql server (within a query) that it's OK to ignore a column if it does not exist in a table?
The use case is:
Some tables have an isDeleted column, but not all of them.
Throughout the application do not return records where isDeleted is TRUE.
Ideally, it would be nice to add this at the lowest level possible in our app so all queries include AND isDeleted=FALSE, but would not break the query if the isDeleted column doesn't exist.
Is it possible to tell sql server (within a query) that it's OK to ignore a column if it does not exist in a table?
No, there isn't.
SQL databases have schemas for a reason - as a programmer it is your responsibility to query your database correctly.
You need to be sure to only query for a isDeleted column on tables that it is defined on.
I am working on a pre-existing MS SQL Server database that was not designed very well. Indexes and primary keys were missing in most cases. There were NO foreign key constraints.
I made a local copy of the DB (so as not to work on the live version), and fixed most of the problems. I now want to syncronize my changes to the production server,
but...
Because there were no previous foreign key constraints there are key mismatches in the tables, thousands of them. I have tried a few synchronization tools, but none of them will allow to ignore or resolve FK mismatches. (in SQL Server Management Studio it's called "Check Existing Data On Creation Or Re-Enabling: No")
Is there a way to auto-resolve the discrepancies of the old database?
Try to use SQL DATA COMPARE from red-gate to syncrhonize data.
https://www.red-gate.com/dynamic/downloads/downloadform.aspx?download=sqldatacompare
You can also try SQL compare to syncrhonize structure, before synchronize data if SQL data compare don't work.
SQL compare
What do you mean by "auto-resolve"?
Existing data is "bad" - that is, the constraints you are trying to impose are violated. There is no way to make your data "good" without modifying it. And there is obviously no way to decide automatically how to fix the data.
So, the best thing you could do is to analyze the data, find out how to correct it, do the corrections manually, and then add the constraints.
You could also just delete all the inconsistent rows (probably a bad idea, if you need the data), or force the server to ignore the constraints for existing data (definitely a bad idea).
If you just want to drop the inconsistent data, I'd suggest you to write (or generate, if there're lots of foreing keys) SQL scripts like this:
DELETE a FROM a LEFT JOIN b ON a.b_id = b.id WHERE b.id IS NULL
ALTER TABLE a ADD CONSTRAINT FK_a_b_id FOREIGN KEY (b_id) REFERENCES b (id)
I'm building an ASP.Net/MVC application using SQL 2008 Developer edition and a DB in Sql2005 compatibility mode. Using Entity Framework as DAL.
My problem is that I have a table where I'm using the integer identity column in a like an Invoice Number, that is, it always has to be unique and never reused. So using the GUID column type won't work without a substantial effort.
What I'm seeing is that the DB is filling in the gaps in the identity column. This will cause me long term problems. Is there a setting to disable this "filling in"
That sounds like something outside SQL server; SQL server does not "go back" and re-use gaps in identities unless the table's been reseeded, but even then it will blindly increment one-by-one and probably return a lot of duplicate key errors as it hits rows with existing values.
Are you sure the column is an identity? Is there anything else that might be re-assigning keys and/or turning on identity insert when creating rows?
SQL Server does not fill in the gaps of an identity field by default it will just keep going up in numbers as you insert rows.
It is possible to reset the identity back to 1 and therefore you may then see what you are describing.
Can I suggest you post some code / db structure that shows your problem and search for any code you may have that my perform an identity reseed.
Unless I am not understanding your issue correctly. If you create a primary key on your identity column, or a unique constraint, you can avoid the issue of duplicate values.
For example:
create table TableName
(
InvoiceID int identity(1,1) not null primary key
)