unique

12 Digit Unique ID - Code reliability

Guys, I wanted a number that would remain unique for a day (24 hours). Following is the code that I came up with; I was wondering about its fallacies/possible risks; 'I believe' this guarantees a 12 digit unique number for a day atleast. Logic is to get the current date/time (hhmmssmmm) and concat the first four bytes of query perform...

IGNORE_DUP_KEY option in SQL Server

Hello everyone, I did quite some search in MSDN and Google, but looks like the description for IGNORE_DUP_KEY option is very limited. My confusions, Is IGNORE_DUP_KEY option an option for a column? for a table? for a couple of columns? for an index (making index unique)? If set IGNORE_DUP_KEY to Yes, when insert a batch of records (u...

Generate File Names Automatically without collision

I'm writing a "file sharing hosting" and I want to rename all the files when uploading to a unique name and somehow keep track of the names on the database. Since I don't want two or more files having same name (which is surely impossible), I'm looking for an algorithm which based on key or something generates random names for me. Moreo...

Sql Query with unique column value

My goal is to get a query written. I have three tables, A, B and C. The tables are written such that A.bID = B.bID, and B.cID = C.cID. This basically allows me to write a query where I link a record from a to b, and link the b record to a record from c. So far so good, simple query. What my problem is... one of the columns included in t...

How to sort 32bit numbers to find unique entries?

Hi, There is a data set of "file" - name of file, and 32bit number is following after it - something like hash for the file. "file1" 6a9bd9a6 1df3b24b 7ab054dc "file2" 6a9bd54e 1df3b24b 8cd054dc "file3" 6a9bd9a6 7ab054dc How am I going to get unique files so s2 is not a prefix of any other s2 - that means the number is unique. If the...

Unique record in Asp.Net SQL

I asked this question previously but the answers weren't what I was looking for. I created a table in Asp.net without using code. It contains two columns. YourUserId and FriendUserId This is a many to many relationship. Heres what I want: There can be multiple records with your name as the UserId, there can also be multiple record...

Any chance to get unique records using Linq (C#)?

Hi, I got a list<list<string>> in list[x][0] are records from which I want to choose unique records thus such record wouldn't be in any other list[x][0], when I choose it, i'd like whole row list[x] to be chosen. I haven't found the appropriate exapmple for this in Linq, please help :( EDIT When Jon Skeet asks me to clarify, I can't ...

Django models - how to filter out duplicate values by PK after the fact?

I build a list of Django model objects by making several queries. Then I want to remove any duplicates, (all of these objects are of the same type with an auto_increment int PK), but I can't use set() because they aren't hashable. Is there a quick and easy way to do this? I'm considering using a dict instead of a list with the id as th...

.NET unique object identifier

Is there any way of getting an unique identifier of an instance? GetHashCode() is same for 2 references pointing to the same instance. However, 2 different instances can (quite early) get same hash code: Hashtable hashCodesSeen = new Hashtable(); LinkedList<object> l = new LinkedList<object>(); int n = 0; while (true) { ob...

Declaring an Index as unique in SQL Server

If I know an index will have unique values, how will it affect performance on inserts or selects if I declare it as such. If the optimiser knows the index is unique how will that affect the query plan? I understand that specifying uniquenes can serve to preserve integrity, but leaving that discussion aside for the moment, what are the...

How to prevent insert of duplicate data with nHibernate?

I'm building a blog/CMS system (for fun, I know there are a ton out there I could use). I have a simple Tag entity that only has an Id (int) and a TagName (string) property. I'd like to configure nHibernate such that I can do something like: var tag1 = Tag.CreateTag("duplicate tag test"); // Id=0 at this point var tag2 = Tag.CreateTag...

Update duplicate varchars to be unique in SQL database

I need to change a database to add a unique constraint on a table column, but the VARCHAR data in it is not unique. How can I update those duplicate records so that each value is unique by adding a sequential number at the end of the existing data? e.g. I would like to change 'name' to 'name1', 'name2', 'name3' ...

What is a good way to generate short and unique file/folder names?

The criteria is basically this: folders will exist for about 24-48hrs folders names can not be readily guessable by a user (if used in a URL) folder names should be short 5-15 chars Initial thoughts: printf('%u',crc32(microtime(true))); Details: When uploading a file, I basically want to keep the unique file name as named by the u...

Can I have a deferrable unique functional index in Oracle?

I'd like to create a deferrable unique functional index in Oracle 10g. I know how to create a unique functional index: create unique index LIST_ITEM_ENTRY_NO_UNIQ on LIST_ITEM (case status when 'cancel' then null else LIST_KEY end, case status when 'cancel' then null else ENTRY_NO end); I know how to create a deferrable...

How do web analytics platforms (GA for example) calculate unique visitors?

Counting distinct visitors is not an easy task. In web analytics for example, a visitor can visit on Monday and Thursday, but when counting unique visitors over that week, I'd expect to count that visitor only once. count (distinct userid) for 10M visits over a month can't run too fast as aggregations can't be applied (because count di...

Sqlite insert into with unique names, getting id

I have a list of strings to insert into a db. They MUST be unique. When i insert i would like their ID (to use as a foreign key in another table) so i use last_insert_rowid. I get 2 problems. If i use replace, their id (INTEGER PRIMARY KEY) updates which breaks my db (entries point to nonexistent IDs) If i use ignore, rowid is not upda...

returning partially distinct/unique rows

Hi all, I need to create a query which groups by two columns and returns an additional column based on a condition. For example, say I've got the following columns: ProductCode | SerialNumber | Quantity | DatePurchased | CustomerID and the table contains duplicate combinations of ProductCode and SerialNumber with differing Quanitite...

SQL 2005 XML Schemas - Defining a Unique Attribute

Here's a Sample xml document I'm trying to create a schema for: '<Fields> <Field ID="-1">somevalue</Field> <Field ID="-2" /> <Field ID="-3" /> <Field ID="-4">Some other value</Field> <Field ID="-5" /> </Fields>' I'm trying to create a SQL Server 2005 schema collection to: 1. prevent dupicate id's. 2. only allow negative ids....

Algorithm to find first index where strings are different?

I've got a collection of strings, and I need to know the first index where they all differ. I can think of two ways to do this: (the following pseudo code is just off the top of my head and may be heavily bug-laden) First Way: var minLength = [go through all strings finding min length]; var set = new set() for(i=0;i<minlength;i++) { ...

Algorithm for unique CD-KEY generation with validation

Hi, I am trying to create a unique CD-KEY to put in our product's box, just like a normal CD-KEY found in standard software boxes that users use to register the product. However we are not selling software, we are selling DNA collection kit for criminal and medical purposes. Users will receive a saliva collection kit by mail with the ...