unique-index

cakephp isUnique for 2 fields?

限于喜欢 提交于 2019-11-27 20:53:23
I have a registration form in which users can fill in two email address (email1 & email2). Marketing's requirement is that they need to be unique (unique as in if we had 10 users, then there would be 10*2=20 unique email address). The system is already built on cakephp, so what I'd like to know is, is there something similar to the isUnique feature (unique in one field) that can do this right out of the box? Or am I doomed to code this myself? Thanks in advance. EDIT: built on Richard's example, this worked for me: function checkUnique($data, $fields) { if (!is_array($fields)) { $fields =

Removing duplicates with unique index

强颜欢笑 提交于 2019-11-27 14:41:06
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 duplicate it. Paul Spiegel If you have duplicates in your table and you use ALTER TABLE mytable ADD UNIQUE

Unique index or unique key?

纵饮孤独 提交于 2019-11-27 11:54:43
问题 What is the diffrence between a unique index and a unique key? 回答1: The unique piece is not where the difference lies. The index and key are not the same thing, and are not comparable. A key is a data column, or several columns, that are forced to be unique with a constraint, either primary key or explicitly defined unique constraint. Whereas an index is a structure for storing data location for faster retrieval. From the docs: Unique Index Creates a unique index on a table or view. A unique

Behavior of unique index, varchar column and (blank) spaces

六眼飞鱼酱① 提交于 2019-11-27 06:03:27
问题 I'm using Microsoft SQL Server 2008 R2 (with latest service pack/patches) and the database collation is SQL_Latin1_General_CP1_CI_AS. The following code: SET ANSI_PADDING ON; GO CREATE TABLE Test ( Code VARCHAR(16) NULL ); CREATE UNIQUE INDEX UniqueIndex ON Test(Code); INSERT INTO Test VALUES ('sample'); INSERT INTO Test VALUES ('sample '); SELECT '>' + Code + '<' FROM Test WHERE Code = 'sample '; GO produces the following results: (1 row(s) affected) Msg 2601, Level 14, State 1, Line 8

Short unique id in php

烂漫一生 提交于 2019-11-27 02:51:23
I want to create a unique id but uniqid() is giving something like '492607b0ee414' . What i would like is something similar to what tinyurl gives: '64k8ra' . The shorter, the better. The only requirements are that it should not have an obvious order and that it should look prettier than a seemingly random sequence of numbers. Letters are preferred over numbers and ideally it would not be mixed case. As the number of entries will not be that many (up to 10000 or so) the risk of collision isn't a huge factor. Any suggestions appreciated. lpfavreau Make a small function that returns random

how to set a column as unique indexer on Sqlite

╄→гoц情女王★ 提交于 2019-11-27 00:53:25
问题 I have 3 columns (_id, column1, column2) _id column has been set as autoincrement In database there are some duplicate records, so I want to prevent duplicate records with setting column1 as unique indexer. How do I set a column as unique indexer on sqlite? Or how do I prevent duplicate records? 回答1: No magic, just SQL: create table yourtablename (_id integer primary key autoincrement, column1 text not null unique, column2 text); _id will not be duplicate in any way because it is primary key,

cakephp isUnique for 2 fields?

旧城冷巷雨未停 提交于 2019-11-26 22:59:42
问题 I have a registration form in which users can fill in two email address (email1 & email2). Marketing's requirement is that they need to be unique (unique as in if we had 10 users, then there would be 10*2=20 unique email address). The system is already built on cakephp, so what I'd like to know is, is there something similar to the isUnique feature (unique in one field) that can do this right out of the box? Or am I doomed to code this myself? Thanks in advance. EDIT: built on Richard's

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

萝らか妹 提交于 2019-11-26 18:44:29
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. Is there a query to remove all the duplicates? Saharsh Shah Add Unique Index on your table: ALTER

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

蹲街弑〆低调 提交于 2019-11-26 14:45:56
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 duplicate the automatically-created index. So taking the docs at their word I'm going to just declare