unique-key

Oracle unique constraint and unique index

拟墨画扇 提交于 2019-12-17 15:39:22
问题 Could someone clarify what is the purpose of having unique index without unique constraint (Oracle)? For example, create table test22(id int, id1 int, tmp varchar(20)); create unique index idx_test22 on test22(id); insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // ok insert into test22(id, id1, tmp) values (1, 2, 'aaa'); // fails, ORA-00001: unique // constraint (TEST.IDX_TEST22) violated So far it looks like there is a constraint. But create table test33(id int not null primary key,

How to find next free unique 4-digit number

大兔子大兔子 提交于 2019-12-14 03:43:08
问题 In my db application I have a requirement for a unique, 4-digit number field for each customer. Up until 9999 I can just use autoincrements, but after that I will have to reuse numbers of customers that have been deleted (there won't be more than 5000 customers at a given time but there may be more than 9999 customers over the lifetime of the system). Question 1: Is there a (My)SQL statement to find the next reusable free number? Question 2: If I get the number, assign it to a new customer

Unique constraint on table column

房东的猫 提交于 2019-12-14 02:21:07
问题 I'm having a table (an existing table with data in it) and that table has a column UserName. I want this UserName to be unique. So I add a constraint like this: ALTER TABLE Users ADD CONSTRAINT [IX_UniqueUserUserName] UNIQUE NONCLUSTERED ([UserName]) Now I keep getting the Error that duplicate users exist in this table. But I have checked the database using the following query: SELECT COUNT(UserId) as NumberOfUsers, UserName FROM Users GROUP BY UserName, UserId ORDER BY UserName This results

Mongo database how to use email as unique key?

旧街凉风 提交于 2019-12-13 17:18:22
问题 I creted a mongodb collection and wanted to mark "email" field as unique in it, so I did this (it's a Java code though language isn't actually important here): IndexOptions indexOptions = new IndexOptions(); indexOptions.unique(true); userCollection.createIndex(Indexes.text("email"), indexOptions); Then I try to insert 2 documents like so: Document doc = new Document(); doc.append("email", "johnny@gmail.com"); doc.append("username", "John"); doc.append("lastname", "Doe"); userCollection

Multiple Unique Columns in SQLite

做~自己de王妃 提交于 2019-12-12 09:29:52
问题 I am trying to create a table where I need it to NOT allow rows where 3 fields are the same. When I create the table in Python using SQLLite, I use the follow, but I hardly get any results at all. It usually stops after writing 2 records, so something is obviously believing its duplicated. CREATE TABLE CorpWalletJournal ( date INT, refID INT, refTypeID INT, ownerName1 TEXT, ownerID1 INT, ownerName2 TEXT, ownerID2 INT, argName1 TEXT, argID1 ID, amount INT, balance INT, reason TEXT, accountKey

Storing email VARCHAR(320) as UNIQUE, #1071 - Specified key was too long; max key length is 767

别等时光非礼了梦想. 提交于 2019-12-12 04:15:53
问题 I have already checked what is the reason of this error. Therefore, I know I am exceeding the limit (767 byte) by trying to set email VARCHAR(320) as a UNIQUE key (320 * 3 = 960 byte). However, I am using MySQL as a database and I need to use the email value as a unique key in my application. Could you please tell me, what should I change to overcome this problem? 回答1: Create a unique index on the first 254 characters or so: create unique index idx_t_email on t(email(254)); Emails should be

How to generate unique 64-bit keys

可紊 提交于 2019-12-11 06:57:31
问题 I would like to generate unique 64-bit keys (pseudo)-randomly to identify objects in our model. I need the keys to be as unique as possible (minimize the probability of collisions when any N keys are used together) across all users of the system. Usual GUIDs are out of the question for now because we're data cheap :). Because I don't foresee needing more than 1 million keys used in the same context, I would think 64-bit is enough (probability of collision would be about ~10e-7). As a side

mysql ON DUPLICATE KEY UPDATE

坚强是说给别人听的谎言 提交于 2019-12-11 03:19:09
问题 I'm stuck on a mySQL query using ON DUPLICATE KEY UPDATE. I'm getting the error: mySQL Error: 1062 - Duplicate entry 'hr2461809-3' for key 'fname' The table looks like this: id int(10) NOT NULL default '0', picid int(10) unsigned NOT NULL default '0', fname varchar(255) NOT NULL default '', type varchar(5) NOT NULL default '.jpg', path varchar(255) NOT NULL default '', PRIMARY KEY (id), UNIQUE KEY fname (fname), KEY picid (propid) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; And the query that's

MySQL: UNIQUE text field using additional HASH field

和自甴很熟 提交于 2019-12-11 01:48:55
问题 In my MySQL DB I have a table defined like: CREATE TABLE `mytablex_cs` ( `id` mediumint(8) unsigned NOT NULL AUTO_INCREMENT, `tag` varchar(6) COLLATE utf8_bin NOT NULL DEFAULT '', `value` text COLLATE utf8_bin NOT NULL, PRIMARY KEY (`id`), KEY `kt` (`tag`), KEY `kv` (`value`(200)) ) ENGINE=MyISAM AUTO_INCREMENT=7 DEFAULT CHARSET=utf8 COLLATE=utf8_bin I need to implement a UNIQUE constraint (key) on the value field. I know that is not yet possible to define a unique index on the entire value

Mongoose unique index not working

拟墨画扇 提交于 2019-12-10 11:42:29
问题 I don's want duplicate usernames to be able to sign-up on my website. So, I place something like this in mongoose model: var userSchema = new mongoose.Schema({ username: { type: String, index: { unique: true }}, password: String }); But when I create a new user in the controller like below, it does not throw an exception and creates a duplicate. mongoose.model('User').create({ username : email, password : password }, function(err, user) { if (err) { // WHY DOES IT NOT THROW ERROR AND GET HERE