unique-constraint

Do i need a special database constraint on this table?

Hi folks, i've got a commenting system in our database. Just like stackoverflow -> each post has a list of comments. kewl. Anonymous people can add a comment or registered users also. In my table, i'm thinking of having the following: Userid int NULLABLE AnonymousNickname varchar(100) NULLABLE AnonymousEmail varchar(200) NULLABLE ...

How to create a unique constraint just on the date part of a datetime?

I'm writing a very simple blog engine for own use (since every blog engine I encountered is too complex). I want to be able to uniquely identify each post by its URL which is something like /2009/03/05/my-blog-post-slug. To accomplish it in the data tier, I want to create a compound unique constraint on (Date, Slug) where Date is only th...

JPA @OneToMany Sets and unique contstaints

I have the following scenario: I have a system full of users. There is a desire to run contests for users who log into the site over a week or so. Therefore I needed to create a new Contest object which would contain both the entries and the winners. I created something like this: private Set<User>; @OneToMany(cascade = CascadeType....

Uniqueness Constraints in MS Access

In a database I'm having to design for MS Access, I have a table called "Measurements", which stores certain measurement parameters (Measured Values, Std Deviation, etc.) - each row has an integer ID as its primary key. Other tables then link to this measurement table using foreign key relationships. Some tables contain two different "m...

Handling NHibernate Exceptions

What's the best practice for handling exceptions in NHibernate? I've got a SubjectRepository with the following: public void Add(Subject subject) { using (ISession session = HibernateUtil.CurrentSession) using (ITransaction transaction = session.BeginTransaction()) { session.Save(subject); ...

How do you validate uniqueness of a pair of ids in Ruby on Rails?

Suppose the following DB migration in Ruby: create_table :question_votes do |t| t.integer :user_id t.integer :question_id t.integer :vote t.timestamps end Suppose further that I wish the rows in the DB contain unique (user_id, question_id) pairs. What is the right dust to put in the model to accompli...

Does CouchDB support unqiue key constraint?

I come from a RDBMS background, and I have an application here which requires good scalability and low latency. I want to give CouchDB a try. However, I need to detect when a particular INSERT operation fails due to a unique key constraint. Does CouchDB support this? I took a look at the docs, but I could not come across anything relevan...

How can I create a SQL unique constraint based on 2 columns ?

I have a Table like this one: |UserId | ContactID | ContactName --------------------------------------- | 12456 | Ax759 | Joe Smith | 12456 | Ax760 | Mary Smith | 12458 | Ax739 | Carl Lewis | 12460 | Ax759 | Chuck Norris | 12460 | Bx759 | Bruce Lee I need to add a constraint to this table s...

MySQL duplicate entry error when no duplicate exists

EDIT: I seem to get the error listed below on every insert no matter what data I try to insert. So maybe my table was corrupted or something? Anyway, here's my question: I have a MySQL table CREATE TABLE `AcpConfig` ( `ndss_id` int(11) NOT NULL default '0', `acp_id` int(11) NOT NULL default '0', `run_date` date NOT NULL default...

Changing MySQL primary key when foreign key contraints exist

I have two already-existing tables which look (in part) roughly like this: CREATE TABLE parent ( old_pk CHAR(8) NOT NULL PRIMARY KEY ) ENGINE=InnoDB; CREATE TABLE child ( parent_key CHAR(8), FOREIGN KEY (parent_key) REFERENCES parent(old_pk) ON UPDATE CASCADE ON DELETE CASCADE ) ENGINE=InnoDB; I want to add a new ...

I can't seem to get the XPATH right for XSD UNIQE Constraint

I've been trying to get the UNIQUE constraint placed on some attributes i have in a fairly basic XSD Schema. I'm using XMLSpy and i'm wanting to put a unique constraint around TEMPLATE.ID for my nodes (ie its important that they remain unique). I've put the below in place and tried the following: Secenario 1 <xs:unique name="uniquevie...

Which dataset row is violating the DB unique constraint?

Hi, I'm writing an application using c# 2005 and Sql Server 2000. I have a table, with a unique constraint and, in the case I am concerned with, I have two users using a form which will (when Save is pressed) update the table. If the table is, say, NAMES( ID int, NAME varchar(20)) and the unique constraint is on NAME, if the first use...

How to make "No Duplicates" column in Sql Server 2008 ?

I have simple table in my SQL Server Database. This table contain two columns: ID int, Name nvarchar(50). The ID column is the primary key for my table. I want the "Name" column to be "(No Duplicates)", like in Microsoft Access, but this column isn't the primary column. How could I do this? ...

How to retrieve data which caused unique constraint violation (via Hibernate)?

Hi, Is there a way to find out which record caused such a violation in Hibernate? Normally you add objects to session and at the end you persist them. If such an error occurs it takes a while to track down which record has violated the constraint. Is there way to find out which record caused (either to "toString() in case of new obje...

how to delete duplicate entries in postgresql?

Hi, I have a problem where I have to add a unique constraint to an existing table. This is fine except that the table has millions of rows already, and many of the rows violate the unique constraint I need to add. What is the fastest approach to removing the offending rows? I have an sql statement which finds the duplicates and deletes...

Unique constraint on multiple columns

I am using an oracle table and have created a unique constraint over four columns. Can these columns within the constraint have NULL in them? ...

Django: How do I validate unique_together from within the model

I have the following: class AccountAdmin(models.Model): account = models.ForeignKey(Account) is_master = models.BooleanField() name = models.CharField(max_length=255) email = models.EmailField() class Meta: unique_together = (('Account', 'is_master'), ('Account', 'username'),) If I then create a new Accou...

How can I add constraints to an ADO.NET Entity?

I know how to mark a group of fields as primary key in ADO.NET entities but i haven't found a way to declare unique constraints or check constraints. Is this feature missing on the designer or on the framework? Thanx. ...

Varchar with trailing spaces as a Primary Key in SQL Server 2008

Is it possible to have a varchar column as a primary key with values like 'a ' and 'a', is gives always this error "Violation of PRIMARY KEY constraint" in MS SQL Server 2008. In Oracle dons't give any error. BTW I'm not implementing this way I'm only trying to migrate the data from oracle to sql server. Regards ...

MySQL: Table structure for a user's "views"

I've got a question to which I've had opposing pieces of advice, would appreciate additional views. My site has users, each with a user_id. These users can view products, and I need to keep track of the unique instances of users viewing specific products. To record a view in a separate views table, I've currently got two options: OPTIO...