unique-index

Removing duplicates with unique index

妖精的绣舞 提交于 2019-12-17 09:49:58
问题 I inserted between two tables fields A,B,C,D, believing I had created a Unique Index on A,B,C,D to prevent duplicates. However I somehow simply made a normal index on those. So duplicates got inserted. It is 20 million record table. If I change my existing index from normal to unique or simply a add a new unique index for A,B,C,D will the duplicates be removed or will adding fail since unique records exist? I'd test it yet it is 30 mil records and I neither wish to mess the table up or

How do I delete all the duplicate records in a MySQL table without temp tables

别说谁变了你拦得住时间么 提交于 2019-12-17 04:27:04
问题 I've seen a number of variations on this but nothing quite matches what I'm trying to accomplish. I have a table, TableA , which contain the answers given by users to configurable questionnaires. The columns are member_id, quiz_num, question_num, answer_num . Somehow a few members got their answers submitted twice. So I need to remove the duplicated records, but make sure that one row is left behind. There is no primary column so there could be two or three rows all with the exact same data.

How does PostgreSQL enforce the UNIQUE constraint / what type of index does it use?

大憨熊 提交于 2019-12-17 02:38:49
问题 I've been trying to sort out the relationship between unique and index in Postgres after reading the docs on index uniqueness being an implementation detail: The preferred way to add a unique constraint to a table is ALTER TABLE ... ADD CONSTRAINT. The use of indexes to enforce unique constraints could be considered an implementation detail that should not be accessed directly. One should, however, be aware that there's no need to manually create indexes on unique columns; doing so would just

MySQL UNIQUE Constraint multiple columns condition

对着背影说爱祢 提交于 2019-12-13 21:49:01
问题 Well, i have a table with 4 columns( id , event_id , group_id , isbn ), where id is PK, event_id and group_id are FK's, and my problem is: I need the isbn number to be unique for each event_id , let me give you some examples of some rows that should be possible and some that should not: id | event_id | group_id | isbn (1,1,1,123) ok (2,1,2,123) ok (3,1,4,123) ok (4,1,7,1234) ok (5,2,8,123) NOT OK, the 'isbn' must be unique for event_id('123' was already used in the first row with event_id = 1

Symfony2 OneToOne relationship becomes either a Unique index or a foreign key?

不想你离开。 提交于 2019-12-13 12:35:34
问题 I'm taking my first steps in Symfony2 entity relations. I have an entity installation, which each has one meter, and one monitor. This translates to a uni-directional relationship, which I defined as such: /** * * @ORM\OneToOne(targetEntity="InfoMeter") * @ORM\JoinColumn(name="meterid", referencedColumnName="id") */ private $meter; /** * * @ORM\OneToOne(targetEntity="InstallationsRtu") * @ORM\JoinColumn(name="monitorid", referencedColumnName="id") */ private $monitor; Each monitor can only be

Constraining a database table so only one row can have a particular value in a column

て烟熏妆下的殇ゞ 提交于 2019-12-13 05:38:37
问题 I am brand new to SQL and I am trying to figure out an error message I get when I try to follow the suggestions in the post here to enforce only one 'Yes' in my column. DROP TABLE team CASCADE CONSTRAINTS PURGE; create table team ( name varchar2(4) NOT NULL UNIQUE, isTeamLead char(3) check (isTeamLead in ('Yes'))); create unique index only_one_yes on team(isTeamLead) (case when col='YES' then 'YES' end); The error report is as follows: Error report - SQL Error: ORA-02158: invalid CREATE INDEX

how to use UNIQUE index correctly?

为君一笑 提交于 2019-12-12 01:39:54
问题 i have 4 fields at DB.i set them become cant duplicate entry.They are: 1. Model Varchar(14) Unique 2. Serial varchar(8) Unique 3. Lot varchar(5) Unique 4. Line char(5) Unique Model Serial Lot Line First data remocon x0001 033a fa 01 and if i have inputed same data it can't recorded. remocon x0001 033a fa 01 but how to make this data success to input if i type like: remocon x0002 033a fa 01 and i want the result like: Model Serial Lot Line remocon x0001 033a fa 01 remocon x0002 033a fa 01 回答1:

Postgres, duplicate unique index

[亡魂溺海] 提交于 2019-12-11 08:15:25
问题 I have a unique index column named "hash" However when I run query: SELECT * FROM urls_0 WHERE hash = '\x0009cb31d8a6c0c64f6877c22a781804'::bytea There are two rows and I can not reindex that index because of unique violation. What happen here. I'm using PostgreSQL 9.3.2 回答1: It could happen if you use CREATE INDEX CONCURRENTLY clause. from documentation: If a problem arises while scanning the table, such as a uniqueness violation in a unique index, the CREATE INDEX command will fail but

MongoDB - Why does the _id index not throwing an error on duplicate entries?

早过忘川 提交于 2019-12-10 23:34:01
问题 I'm completely new to NoSQL databases and I'm working currently with MongoDB. I'm trying to understand why the default _id index does not throw an error, when upserting a duplicate _id document. As stated in the docs _id is an unique index by default (although it doesn't show the unique flag here..) > db.foo.getIndexes(); [ { "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "test.foo" } ] > So when upserting the document (started with an empty collection), if first inserts it and then

Enforcement of unique/primary key - drop index

夙愿已清 提交于 2019-12-10 14:05:01
问题 I am trying to drop an index : DROP INDEX PK_CHARGES but I get this error cannot drop index used for enforcement of unique/primary key Why I am getting this error? I will provide further information if you need any. How to solve it? Edit I have no primary key in the table, but I found this weird index that I don't remember I had added: index name = SYS_C0040476 which have the same columns 回答1: You can query the ALL_CONSTRAINTS performance view to see which constraint the index is used by, and