unique-key

How to set a field containing unique key

孤街醉人 提交于 2019-12-10 11:39:53
问题 I want to save data in CouchDB documents and as I am used to doing it in RDBMS. I want to create a field which can only contain a unique value in the database. If I now save a document and there is already a document with unique key I expect an error from CouchDB. I guess I can use the document ID and replace the auto generated doc-id by my value, but is there a way to set other field as unique key holder. Any best practice regarding unique keys? 回答1: As you said, the generated _id is

Add new keys to a dictionary while incrementing existing values

▼魔方 西西 提交于 2019-12-09 16:06:39
问题 I am processing a CSV file and counting the unique values of column 4. So far I have coded this three ways. One uses "if key in dictionary", the second traps the KeyError and the third uses "DefaultDictionary". For example (where x[3] is the value from the file and "a" is a dictionary): First way: if x[3] in a: a[x[3]] += 1 else: a[x[3]] = 1 Second way: try: b[x[3]] += 1 except KeyError: b[x[3]] = 1 Third way: from collections import defaultdict c = defaultdict(int) c[x[3]] += 1 My question

How to add an EF6 Association to a Candidate Key / Unique Key which is not the Primary Key?

被刻印的时光 ゝ 提交于 2019-12-09 02:36:15
问题 Using Schema First , I have a database structure, as so ExternalDataItems --- edataitem_id PK -- surrogate auto-increment - NOT for FK relation here datahash UX -- Candidate Key / Unique Index (binary(20)) ExternalMaps --- emap_id PK ext_datahash FK on ExternalDataItems.datahash - NOT referencing the surrogate PK and after generating the SSDL/CSDL 1 has this <Association Name="FK_ExtMaps_ExtDataItems"> <End Multiplicity="1" Role="ExternalDataItems" Type="Store.ExternalDataItems" /> <End

PostgreSQL: is it possible to provide custom name for PRIMARY KEY or UNIQUE?

天大地大妈咪最大 提交于 2019-12-08 16:37:59
问题 When I write: CREATE TABLE accounts ( username varchar(64) PRIMARY KEY, I get primary key named: accounts_pkey Is it possible to assign my own custom name, for instance "accounts_primary_key"? Same story about UNIQUE . I couldn't find it in PostgreSQL documentation. Thanks in advance. 回答1: The trick is the CONSTRAINT part in the column_constraint section of CREATE TABLE . Example: > create table x(xx text constraint xxxx primary key); NOTICE: CREATE TABLE / PRIMARY KEY will create implicit

Setting MySQL unique key or checking for duplicate in application part?

那年仲夏 提交于 2019-12-08 12:09:39
问题 Which one is more reliable and has better performance? Setting MySQL unique key and using INSERT IGNORE or first checking if data exists on database and act according to the result? If the answer is the second one, is there any way to make a single SQL query instead of two? UPDATE: I ask because my colleagues in the company I work believe that deal with such issues should be done in application part which is more reliable according to them. 回答1: You application won't catch duplicates. Two

MySQL: Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available

北城余情 提交于 2019-12-08 07:04:31
问题 I have read all the posts regarding my issue in SO. But nothing fixed this. Issue: When runs the mentioned query, below warning appears. Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Below is my query. SELECT ST.stock_code, S.supplier_name, I.item_name, P.avail_qty, SL.unit_price, P.expire_date FROM purchase_items P INNER JOIN stock ST ON P.stock_id = ST.stock_id INNER JOIN suppliers S ON ST.sup_id = S.sup_id INNER

MyISAM unique keys being cut off at 64 bytes, causing collisions

老子叫甜甜 提交于 2019-12-07 05:11:08
问题 I've got a MySQL table that stores urls as unique keys. I'm starting to get collisions on my keys because it seems the keys themselves are only the first 64 bytes (or characters if you prefer, its a latin-1 collated) of any url. So if a url is over 64 characters and I've already got a similar url it throws an error. For example: SELECT l.link_id FROM mydb.links l WHERE url = 'http://etonline.com/tv/108475_Charlie_Sheen_The_People_Have_Elected_Me_as_Their_Leader/index.html' Throws this error:

MySQL: Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available

こ雲淡風輕ζ 提交于 2019-12-07 02:10:27
I have read all the posts regarding my issue in SO. But nothing fixed this. Issue: When runs the mentioned query, below warning appears. Current selection does not contain a unique column. Grid edit, checkbox, Edit, Copy and Delete features are not available. Below is my query. SELECT ST.stock_code, S.supplier_name, I.item_name, P.avail_qty, SL.unit_price, P.expire_date FROM purchase_items P INNER JOIN stock ST ON P.stock_id = ST.stock_id INNER JOIN suppliers S ON ST.sup_id = S.sup_id INNER JOIN items I ON P.item_id = I.item_id INNER JOIN sales SL ON P.item_id = SL.item_id WHERE (P.expire_date

MySQL UUID() when not unique?

China☆狼群 提交于 2019-12-06 11:04:53
问题 What happens when a UUID() generated by MySQL is not unique? If this is for a column that is a primary key, does MySQL error out, or does it try generating another UUID until a truly unique one is found? 回答1: Well, if you call UUID() twice and get the same results, the most problematic thing would be that "stuff is broken" (tm). It's supposed to be unique and it should be always, as far as I know. There would be no "regenerate" code available: the function is designed to create unique keys

Primary Key Identity Value Increments On Unique Key Constraint Violation

孤街醉人 提交于 2019-12-06 07:10:36
问题 I have a SqlServer 2008 table which has a Primary Key (IsIdentity=Yes) and three other fields that make up a Unique Key constraint. In addition I have a store procedure that inserts a record into the table and I call the sproc via C# using a SqlConnection object. The C# sproc call works fine, however I have noticed interesting results when the C# sproc call violates the Unique Key constraint.... When the sproc call violates the Unique Key constraint, a SqlException is thrown - which is no